Skip to content

prom-client-net/prom-client-metricserver

Repository files navigation

Prometheus.Client.MetricServer

ci nuget nuget codecov license

Extension for Prometheus.Client

Install

dotnet add package Prometheus.Client.MetricServer

Use

Examples

Simple Console App with static MetricFactory:

public static void Main(string[] args)
{
    var options = new MetricServerOptions
    {
        Port = 9091
    };

    var metricServer = new MetricServer(options);
    metricServer.Start();

    var counter = Metrics.DefaultFactory.CreateCounter("test_count", "helptext");
    counter.Inc();

    metricServer.Stop();
}

Worker with DI Prometheus.Client.DependencyInjection:

public static async Task Main(string[] args)
{
    var host = Host.CreateDefaultBuilder(args)
        .ConfigureServices((_, services) =>
        {
            services.AddMetricFactory();
            services.AddSingleton<IMetricServer>(sp => new MetricServer(
                new MetricServerOptions
                {
                    CollectorRegistry = sp.GetRequiredService<ICollectorRegistry>(),
                    UseDefaultCollectors = true
                }));
            services.AddHostedService<Worker>();
        }).Build();

    var metricServer = host.Services.GetRequiredService<IMetricServer>();

    try
    {
        metricServer.Start();
        await host.RunAsync();
    }
    catch (Exception ex)
    {
        Console.WriteLine("Host Terminated Unexpectedly");
    }
    finally
    {
        metricServer.Stop();
    }
}

License

All contents of this package are licensed under the MIT license.

About

Standalone Kestrel server

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors 10

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy