Prometheus.Client.Abstractions 5.2.0

Prefix Reserved
dotnet add package Prometheus.Client.Abstractions --version 5.2.0                
NuGet\Install-Package Prometheus.Client.Abstractions -Version 5.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Prometheus.Client.Abstractions" Version="5.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Prometheus.Client.Abstractions --version 5.2.0                
#r "nuget: Prometheus.Client.Abstractions, 5.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Prometheus.Client.Abstractions as a Cake Addin
#addin nuget:?package=Prometheus.Client.Abstractions&version=5.2.0

// Install Prometheus.Client.Abstractions as a Cake Tool
#tool nuget:?package=Prometheus.Client.Abstractions&version=5.2.0                

Prometheus.Client

ci nuget nuget codecov codefactor license

.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

General use case benchmarks Find more details on benchmarks description

Installation

dotnet add package Prometheus.Client

Configuration

Examples

Prometheus Docs

Quick start

  1. Add IMetricFactory and ICollectorRegistry into DI container with extension library Prometheus.Client.DependencyInjection
public void ConfigureServices(IServiceCollection services)
{
    services.AddMetricFactory();
}
  1. 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!

Supporters

JetBrains Promitor

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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework 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 tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Prometheus.Client.Abstractions:

Package Downloads
Prometheus.Client

.NET client for Prometheus

Itselves.AlertManager.Prometheus

Library for alert manager which use prometheus like a provider

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.2.0 1,681,716 1/5/2023
5.1.0 192,198 9/11/2022
5.0.0 908,667 8/21/2022
4.5.3 808,559 9/20/2021
4.5.2 368,581 7/14/2021
4.5.1 114,869 7/12/2021
4.5.0 1,560 7/10/2021
4.4.0 196,588 3/11/2021
4.3.0 203,727 1/29/2021