Prometheus.Client
5.2.0
dotnet add package Prometheus.Client --version 5.2.0
NuGet\Install-Package Prometheus.Client -Version 5.2.0
<PackageReference Include="Prometheus.Client" Version="5.2.0" />
paket add Prometheus.Client --version 5.2.0
#r "nuget: Prometheus.Client, 5.2.0"
// Install Prometheus.Client as a Cake Addin
#addin nuget:?package=Prometheus.Client&version=5.2.0
// Install Prometheus.Client as a Cake Tool
#tool nuget:?package=Prometheus.Client&version=5.2.0
Prometheus.Client
.NET Client library for prometheus.io
It was started as a fork of prometheus-net, but over time the library was evolved into a different product. 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.
Performance comparison with prometheus-net
Find more details on benchmarks description
Installation
dotnet add package Prometheus.Client
Configuration
Quick start
- Add IMetricFactory and ICollectorRegistry into DI container with extension library Prometheus.Client.DependencyInjection
public void ConfigureServices(IServiceCollection services)
{
services.AddMetricFactory();
}
- Add metrics endpoint
With Prometheus.Client.AspNetCore:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
{
app.UsePrometheusServer();
}
Without extensions:
[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);
}
}
For collect http requests, use Prometheus.Client.HttpRequestDurations. It does not depend of 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();
Extensions
AspNetCore Middleware: Prometheus.Client.AspNetCore
dotnet add package Prometheus.Client.AspNetCore
DependencyInjection support: Prometheus.Client.DependencyInjection
dotnet add package Prometheus.Client.DependencyInjection
Collect http requests duration: Prometheus.Client.HttpRequestDurations
dotnet add package Prometheus.Client.HttpRequestDurations
Push metrics to a PushGateway: Prometheus.Client.MetricPusher
dotnet add package Prometheus.Client.MetricPusher
Standalone Kestrel host: Prometheus.Client.MetricServer
dotnet add package Prometheus.Client.MetricServer
HealthChecks Publisher Prometheus.Client.HealthChecks
dotnet add package Prometheus.Client.HealthChecks
Contribute
Contributions to the package are always welcome!
- Report any bugs or issues you find on the issue tracker.
- You can grab the source code at the package's git repository.
Supporters
We much appreciate free licenses provided by JetBrains to support our library.
Thanks Promitor for supporting us via GitHub Sponsors.
License
All contents of this package are licensed under the MIT license.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- Prometheus.Client.Abstractions (>= 5.2.0)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
-
.NETStandard 2.1
- Prometheus.Client.Abstractions (>= 5.2.0)
NuGet packages (24)
Showing the top 5 NuGet packages that depend on Prometheus.Client:
Package | Downloads |
---|---|
Prometheus.Client.AspNetCore
ASP.NET Core middleware for the Prometheus.Client |
|
Prometheus.Client.HttpRequestDurations
Metrics logging of request durations for the Prometheus.Client |
|
Prometheus.Client.MetricPusher
Push metrics to a PushGateaway for the Prometheus.Client |
|
Prometheus.Client.DependencyInjection
Microsoft.Extensions.DependencyInjection (IServiceCollection) support for the Prometheus.Client |
|
Prometheus.Client.HealthChecks
HealthChecks middleware for the Prometheus.Client |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Prometheus.Client:
Repository | Stars |
---|---|
RayTale/Ray
项目停止更新,新项目:https://github.com/RayTale/Vertex
|
|
tomkerkhove/promitor
Bringing Azure Monitor metrics where you need them.
|
Version | Downloads | Last updated |
---|---|---|
5.2.0 | 15,142 | 1/5/2023 |
5.1.0 | 84,369 | 9/11/2022 |
5.0.0 | 31,237 | 8/21/2022 |
4.5.3 | 457,581 | 9/20/2021 |
4.5.2 | 178,200 | 7/14/2021 |
4.5.1 | 55,574 | 7/12/2021 |
4.4.0 | 131,946 | 3/11/2021 |
4.3.0 | 187,664 | 1/29/2021 |
4.2.0 | 109,886 | 10/21/2020 |
4.1.0 | 174,999 | 8/19/2020 |
3.1.0 | 754,928 | 1/10/2020 |
3.0.3 | 102,235 | 10/2/2019 |
3.0.2 | 95,583 | 9/4/2019 |
3.0.1 | 155,121 | 5/23/2019 |
3.0.0-rc2 | 763 | 4/1/2019 |
3.0.0-rc1 | 29,201 | 3/24/2019 |
2.2.2 | 392,622 | 3/1/2019 |
2.2.1 | 2,617 | 2/26/2019 |
2.2.0 | 131,373 | 2/10/2019 |
2.1.0 | 196,347 | 1/24/2019 |
2.0.0 | 398,766 | 9/13/2018 |
1.5.1 | 23,188 | 6/17/2018 |
1.5.0 | 14,243 | 4/22/2018 |
1.4.1 | 39,093 | 3/4/2018 |
1.4.0 | 89,534 | 12/3/2017 |
1.3.0 | 9,072 | 11/12/2017 |
1.2.2 | 1,095 | 11/9/2017 |
1.2.1 | 2,317 | 10/8/2017 |
1.1.3 | 886 | 10/8/2017 |
1.1.2 | 5,213 | 7/30/2017 |
1.1.1 | 1,390 | 6/7/2017 |
1.1.0 | 5,790 | 5/9/2017 |
1.0.0 | 2,006 | 5/8/2017 |
1.0.0-alpha2 | 5,728 | 3/6/2017 |
1.0.0-alpha1 | 790 | 3/3/2017 |