RepositoryC#
prom-client-net

prom-client-net/prom-client

.NET client for Prometheus

142stars
21forks
1issues
0views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: prometheus-client

#1 Repository of the month

Prometheus.Client

ci nuget nuget codecov license

.NET Client library for prometheus.io

It is hard fork of prometheus-net from early 2017 that has since evolved into a different library.

Our main goals:

  • Keep possibility of rapid development.
  • Extensibility is one of the core values, together with performance and minimal allocation.
  • We are open for suggestions and new ideas, contribution is always welcomed.

You can find the benchmark descriptions.

Install

dotnet add package Prometheus.Client

Extensions

NameDescription
Prometheus.Client.AspNetCoreASP.NET Core middleware
Prometheus.Client.DependencyInjectionDependency Injection extensions
Prometheus.Client.HttpRequestDurationsMetrics logging of request durations
Prometheus.Client.MetricPusherPush metrics to Prometheus PushGateway
Prometheus.Client.MetricPusher.HostedServiceMetricPusher as HostedService
Prometheus.Client.HealthChecksHealthChecks Publisher
Prometheus.Client.MetricServerStandalone Kestrel server
Prometheus.Client.OwinOwin middleware

Use

Examples

Prometheus Docs

Add metrics endpoint without extension:

[Route("[controller]")]
public class MetricsController : Controller
{
    private readonly ICollectorRegistry _registry;

    public MetricsController(ICollectorRegistry registry)
    {
        _registry = registry;
    }

    [HttpGet]
    public async Task Get()
    {
        Response.StatusCode = 200;
        await using var outputStream = Response.Body;
        await ScrapeHandler.ProcessAsync(_registry, outputStream);
    }
}

Add metrics endpoint with Prometheus.Client.AspNetCore:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
{
    app.UsePrometheusServer();
}

IMetricFactory and ICollectorRegistry can be added to DI container with Prometheus.Client.DependencyInjection:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMetricFactory();
}

For collect http requests, use Prometheus.Client.HttpRequestDurations. It does not depend on Prometheus.Client.AspNetCore, however together it's very convenient to use:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
{
    app.UsePrometheusServer();
    app.UsePrometheusRequestDurations();
}

Instrumenting

Four types of metric are offered: Counter, Gauge, Summary and Histogram. See the documentation on metric types and instrumentation best practices on how to use them.

Counter

Counters go up, and reset when the process restarts.

var counter = metricFactory.CreateCounter("myCounter", "some help about this");
counter.Inc(5.5);

Gauge

Gauges can go up and down.

var gauge = metricFactory.CreateGauge("gauge", "help text");
gauge.Inc(3.4);
gauge.Dec(2.1);
gauge.Set(5.3);

Summary

Summaries track the size and number of events.

var summary = metricFactory.CreateSummary("mySummary", "help text");
summary.Observe(5.3);

Histogram

Histograms track the size and number of events in buckets. This allows for aggregate calculation of quantiles.

var hist = metricFactory.CreateHistogram("my_histogram", "help text", buckets: new[] { 0, 0.2, 0.4, 0.6, 0.8, 0.9 });
hist.Observe(0.4);

The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds. They can be overridden passing in the buckets argument.

Labels

All metrics can have labels, allowing grouping of related time series.

See the best practices on naming and labels.

Taking a counter as an example:

var counter = metricFactory.CreateCounter("myCounter", "help text", labelNames: new []{ "method", "endpoint"});
counter.WithLabels("GET", "/").Inc();
counter.WithLabels("POST", "/cancel").Inc();

Since v4 there is alternative new way to provide a labels via ValueTuple that allow to reduce memory allocation:

var counter = metricFactory.CreateCounter("myCounter", "help text", labelNames: ("method", "endpoint"));
counter.WithLabels(("GET", "/")).Inc();
counter.WithLabels(("POST", "/cancel")).Inc();

Contribute

Contributions to the package are always welcome!

Supporters

Entity Framework Extensions is a major sponsor and is proud to contribute to this project.

Entity Framework Extensions

License

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

Similar Projects

Discover other similar projects and AI models.

RepositoryGo
grafana/grafana

The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

78.4k
Nov 30, 2026
RepositoryGo
prometheus/prometheus

The Prometheus monitoring system and time series database.

68.1k
Dec 2, 2026
RepositoryJava
apache/skywalking

APM, Application Performance Monitoring System

25.0k
Nov 27, 2026
RepositoryTypeScript
openobserve/openobserve

Open source observability platform for logs, metrics, traces, RUM (web, android, ios), Session replay, pipelines, SLO and LLM observability. A sophisticated, simple and highly performant alternative to Datadog, Splunk, and Elasticsearch with 140x lower storage costs and single binary deployment.

23.2k
Nov 27, 2026
RepositoryGo
prometheus/node_exporter

Exporter for machine metrics

14.0k
Dec 1, 2026
RepositoryGo
prometheus/node_exporter

Exporter for machine metrics

14.0k
Nov 30, 2026
RepositoryGo
coroot/coroot

Coroot is an open-source observability and APM tool with AI-powered Root Cause Analysis. It combines metrics, logs, traces, continuous profiling, and SLO-based alerting with predefined dashboards and inspections.

8.0k
Nov 19, 2026
RepositoryGo
kubernetes/kube-state-metrics

Add-on agent to generate and expose cluster-level metrics.

6.2k
Dec 1, 2026
RepositoryGo
grafana/mimir

Grafana Mimir provides horizontally scalable, highly available, multi-tenant, long-term storage for Prometheus.

5.3k
Nov 30, 2026