Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork22
prom-client-net/prom-client
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
.NET Client library forprometheus.io
It is hard fork ofprometheus-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 thebenchmark descriptions.
dotnet add package Prometheus.Client
Name | Description |
---|---|
Prometheus.Client.AspNetCore | ASP.NET Core middleware |
Prometheus.Client.DependencyInjection | Dependency Injection extensions |
Prometheus.Client.HttpRequestDurations | Metrics logging of request durations |
Prometheus.Client.MetricPusher | Push metrics to Prometheus PushGateway |
Prometheus.Client.MetricPusher.HostedService | MetricPusher as HostedService |
Prometheus.Client.HealthChecks | HealthChecks Publisher |
Prometheus.Client.MetricServer | Standalone Kestrel server |
Prometheus.Client.Owin | Owin middleware |
Add metrics endpoint without extension:
[Route("[controller]")]publicclassMetricsController:Controller{privatereadonlyICollectorRegistry_registry;publicMetricsController(ICollectorRegistryregistry){_registry=registry;}[HttpGet]publicasyncTaskGet(){Response.StatusCode=200;awaitusingvaroutputStream=Response.Body;awaitScrapeHandler.ProcessAsync(_registry,outputStream);}}
Add metrics endpoint withPrometheus.Client.AspNetCore:
publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv,ILoggerFactoryloggerFactory,IApplicationLifetimeappLifetime){app.UsePrometheusServer();}
IMetricFactory
andICollectorRegistry
can be added to DI container withPrometheus.Client.DependencyInjection:
publicvoidConfigureServices(IServiceCollectionservices){services.AddMetricFactory();}
For collect http requests, usePrometheus.Client.HttpRequestDurations.It does not depend onPrometheus.Client.AspNetCore, however together it's very convenient to use:
publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv,ILoggerFactoryloggerFactory,IApplicationLifetimeappLifetime){app.UsePrometheusServer();app.UsePrometheusRequestDurations();}
Four types of metric are offered:Counter
,Gauge
,Summary
andHistogram
.See the documentation onmetric typesandinstrumentation best practiceson how to use them.
Counters go up, and reset when the process restarts.
varcounter=metricFactory.CreateCounter("myCounter","some help about this");counter.Inc(5.5);
Gauges can go up and down.
vargauge=metricFactory.CreateGauge("gauge","help text");gauge.Inc(3.4);gauge.Dec(2.1);gauge.Set(5.3);
Summaries track the size and number of events.
varsummary=metricFactory.CreateSummary("mySummary","help text");summary.Observe(5.3);
Histograms track the size and number of events in buckets.This allows for aggregate calculation of quantiles.
varhist=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 thebuckets
argument.
All metrics can have labels, allowing grouping of related time series.
See the best practices onnamingandlabels.
Taking a counter as an example:
varcounter=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:
varcounter=metricFactory.CreateCounter("myCounter","help text",labelNames:("method","endpoint"));counter.WithLabels(("GET","/")).Inc();counter.WithLabels(("POST","/cancel")).Inc();
Contributions to the package are always welcome!
- Report any bugs or issues you find on theissue tracker.
- You can grab the source code at the package'sgit repository.
Entity Framework Extensions is a major sponsor and is proud to contribute to this project.
All contents of this package are licensed under theMIT license.
About
.NET client for Prometheus
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.