Prometheus.Client
1.4.1
Prefix Reserved
See the version list below for details.
dotnet add package Prometheus.Client --version 1.4.1
NuGet\Install-Package Prometheus.Client -Version 1.4.1
<PackageReference Include="Prometheus.Client" Version="1.4.1" />
paket add Prometheus.Client --version 1.4.1
#r "nuget: Prometheus.Client, 1.4.1"
// Install Prometheus.Client as a Cake Addin #addin nuget:?package=Prometheus.Client&version=1.4.1 // Install Prometheus.Client as a Cake Tool #tool nuget:?package=Prometheus.Client&version=1.4.1
Prometheus.Client
.NET Client library(unofficial) for prometheus.io
Support .net45, .netstandard1.3 and .netstandard2.0
It's a fork of prometheus-net
Installation
Install-Package Prometheus.Client
Extension for WEB: Prometheus.Client.Owin
Install-Package Prometheus.Client.Owin
Extension for Standalone host: Prometheus.Client.MetricServer
Install-Package Prometheus.Client.MetricServer
Extension for collect http request duration from all requests: Prometheus.Client.HttpRequestDurations
Install-Package Prometheus.Client.HttpRequestDurations
Quik start
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
{
var options = new PrometheusOptions();
app.UsePrometheusServer(options);
}
Without extensions:
[Route("[controller]")]
public class MetricsController : Controller
{
[HttpGet]
public void Get()
{
var registry = CollectorRegistry.Instance;
var acceptHeaders = Request.Headers["Accept"];
var contentType = ScrapeHandler.GetContentType(acceptHeaders);
Response.ContentType = contentType;
Response.StatusCode = 200;
using (var outputStream = Response.Body)
{
var collected = registry.CollectAll();
ScrapeHandler.ProcessScrapeRequest(collected, contentType, outputStream);
}
}
}
See prometheus here
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 = Metrics.CreateCounter("myCounter", "some help about this");
counter.Inc(5.5);
Gauge
Gauges can go up and down.
var gauge = Metrics.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 = Metrics.CreateSummary("mySummary", "help text");
summary.Observe(5.3);
Histogram
Histograms track the size and number of events in buckets. This allows for aggregatable calculation of quantiles.
var hist = Metrics.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 = Metrics.CreateCounter("myCounter", "help text", labelNames: new []{ "method", "endpoint"});
counter.Labels("GET", "/").Inc();
counter.Labels("POST", "/cancel").Inc();
Unit testing
For simple usage the API uses static classes, which - in unit tests - can cause errors like this: "A collector with name '<NAME>' has already been registered!"
To address this you can add this line to your test setup:
CollectorRegistry.Instance.Clear();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- protobuf-net (>= 2.3.7)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- protobuf-net (>= 2.3.7)
- System.Diagnostics.Process (>= 4.3.0)
-
.NETStandard 2.0
- protobuf-net (>= 2.3.7)
NuGet packages (23)
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.DependencyInjection
Dependency Injection extensions for Prometheus.Client |
|
Prometheus.Client.HealthChecks
Implements IHealthCheckPublisher for Prometheus.Client |
|
Prometheus.Client.HttpRequestDurations
HTTP request durations for the Prometheus.Client |
|
Prometheus.Client.MetricPusher
Push metrics to PushGateaway for 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 | 1,998,596 | 1/5/2023 |
5.1.0 | 195,004 | 9/11/2022 |
5.0.0 | 934,067 | 8/21/2022 |
4.5.3 | 827,403 | 9/20/2021 |
4.5.2 | 395,134 | 7/14/2021 |
4.5.1 | 123,622 | 7/12/2021 |
4.4.0 | 207,131 | 3/11/2021 |
4.3.0 | 204,010 | 1/29/2021 |
4.2.0 | 131,935 | 10/21/2020 |
4.1.0 | 212,127 | 8/19/2020 |
3.1.0 | 1,063,123 | 1/10/2020 |
3.0.3 | 124,741 | 10/2/2019 |
3.0.2 | 96,348 | 9/4/2019 |
3.0.1 | 204,248 | 5/23/2019 |
3.0.0-rc2 | 1,882 | 4/1/2019 |
3.0.0-rc1 | 38,515 | 3/24/2019 |
2.2.2 | 553,307 | 3/1/2019 |
2.2.1 | 4,034 | 2/26/2019 |
2.2.0 | 428,594 | 2/10/2019 |
2.1.0 | 223,821 | 1/24/2019 |
2.0.0 | 697,995 | 9/13/2018 |
1.5.1 | 25,081 | 6/17/2018 |
1.5.0 | 19,582 | 4/22/2018 |
1.4.1 | 40,948 | 3/4/2018 |
1.4.0 | 103,953 | 12/3/2017 |
1.3.0 | 13,626 | 11/12/2017 |
1.2.2 | 1,814 | 11/9/2017 |
1.2.1 | 3,105 | 10/8/2017 |
1.1.3 | 1,570 | 10/8/2017 |
1.1.2 | 6,055 | 7/30/2017 |
1.1.1 | 2,155 | 6/7/2017 |
1.1.0 | 8,423 | 5/9/2017 |
1.0.0 | 3,724 | 5/8/2017 |
1.0.0-alpha2 | 6,648 | 3/6/2017 |
1.0.0-alpha1 | 1,531 | 3/3/2017 |