NetEvolve.HealthPublishers.Prometheus.Metrics 1.10.0

Prefix Reserved
dotnet add package NetEvolve.HealthPublishers.Prometheus.Metrics --version 1.10.0
                    
NuGet\Install-Package NetEvolve.HealthPublishers.Prometheus.Metrics -Version 1.10.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="NetEvolve.HealthPublishers.Prometheus.Metrics" Version="1.10.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetEvolve.HealthPublishers.Prometheus.Metrics" Version="1.10.0" />
                    
Directory.Packages.props
<PackageReference Include="NetEvolve.HealthPublishers.Prometheus.Metrics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetEvolve.HealthPublishers.Prometheus.Metrics --version 1.10.0
                    
#r "nuget: NetEvolve.HealthPublishers.Prometheus.Metrics, 1.10.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.
#:package NetEvolve.HealthPublishers.Prometheus.Metrics@1.10.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetEvolve.HealthPublishers.Prometheus.Metrics&version=1.10.0
                    
Install as a Cake Addin
#tool nuget:?package=NetEvolve.HealthPublishers.Prometheus.Metrics&version=1.10.0
                    
Install as a Cake Tool

NetEvolve.HealthPublishers.Prometheus.Metrics

NuGet Version NuGet Downloads License

An IHealthCheckPublisher implementation that updates prometheus-net Gauge metrics in an in-process CollectorRegistry on every publish, reflecting the latest HealthReport results, ready to be scraped by Prometheus.

Pull vs. push

This package complements NetEvolve.HealthPublishers.Prometheus.PushGateway, which pushes metrics over HTTP to a Prometheus Pushgateway instance on every publish. This package instead follows the standard Prometheus pull/scrape model: it only mutates in-process gauge state, it never performs any HTTP call. Scraping is handled entirely by prometheus-net's own ASP.NET Core middleware (e.g. AspNetCoreExporterExtensions.MapMetrics / UseMetricServer, from the prometheus-net.AspNetCore package), which the consuming application must wire up separately.

Because a library should not silently pollute an application's global default CollectorRegistry, every registration of this publisher gets its own dedicated CollectorRegistry, created via Metrics.NewCustomRegistry(). This registry is registered in the DI container as a keyed singleton, keyed by the publisher's name ("Default" unless an explicit name is used). The consuming application resolves it and passes it explicitly to the prometheus-net middleware:

using Prometheus;

var registry = app.Services.GetRequiredKeyedService<CollectorRegistry>("Default");

app.MapMetrics("/metrics", registry: registry);

Features

  • Updates a full set of gauges on every publish: overall report status, report duration, last publish timestamp, and per-check status and duration
  • Maps HealthStatus to a numeric gauge value using the enum's own ordinal (Unhealthy0, Degraded1, Healthy2)
  • Labels every gauge with the machine name and a required, free-form SystemIdentifier to tell instances apart
  • Removes stale per-check gauge series for checks that no longer appear in a later report, so the registry always reflects only the latest health report
  • Configuration- or builder-based setup, consistent with the NetEvolve.HealthChecks.* conventions
  • Named registrations, each with its own dedicated CollectorRegistry, to keep multiple publisher setups fully isolated from each other and from the global default registry

Installation

NuGet Package Manager

Install-Package NetEvolve.HealthPublishers.Prometheus.Metrics

.NET CLI

dotnet add package NetEvolve.HealthPublishers.Prometheus.Metrics

PackageReference

<PackageReference Include="NetEvolve.HealthPublishers.Prometheus.Metrics" Version="x.x.x" />

Quick Start

using NetEvolve.HealthPublishers.Prometheus.Metrics;

var builder = services.AddHealthChecks();

builder.AddPrometheusMetricsPublisher(options =>
{
    options.SystemIdentifier = "checkout-service";
});

Then, separately, wire up prometheus-net's ASP.NET Core middleware against the dedicated registry (requires the prometheus-net.AspNetCore package):

using Prometheus;

app.MapMetrics("/metrics", registry: app.Services.GetRequiredKeyedService<CollectorRegistry>("Default"));

Usage

Basic Example

Register under the default name ("Default"), configured via code:

var builder = services.AddHealthChecks();

builder.AddPrometheusMetricsPublisher(options =>
{
    options.SystemIdentifier = "checkout-service"; // Required, labels every gauge alongside the machine name
});

Advanced Example

Register multiple named publishers, each with its own dedicated CollectorRegistry and, therefore, its own /metrics endpoint:

var builder = services.AddHealthChecks();

builder.AddPrometheusMetricsPublisher("Internal", options => options.SystemIdentifier = "checkout-service");
builder.AddPrometheusMetricsPublisher("External", options => options.SystemIdentifier = "checkout-service");
using Prometheus;

app.MapMetrics("/metrics/internal", registry: app.Services.GetRequiredKeyedService<CollectorRegistry>("Internal"));
app.MapMetrics("/metrics/external", registry: app.Services.GetRequiredKeyedService<CollectorRegistry>("External"));

Configuration

Code-based

builder.AddPrometheusMetricsPublisher(options =>
{
    options.SystemIdentifier = "checkout-service"; // Required
});

appsettings.json-based

builder.AddPrometheusMetricsPublisher(); // reads the "Default" section below
{
  "HealthPublishers": {
    "Prometheus": {
      "Metrics": {
        "Default": {
          "SystemIdentifier": "checkout-service"
        }
      }
    }
  }
}

When using an explicit name, the section key must match: builder.AddPrometheusMetricsPublisher("Internal") reads HealthPublishers:Prometheus:Metrics:Internal.

Published Metrics

Metric Type Labels Description
healthcheck_report_status gauge system_identifier, machine_name Overall health report status (0/1/2)
healthcheck_report_duration_seconds gauge system_identifier, machine_name Total duration of the health report execution
healthcheck_last_publish_timestamp_seconds gauge system_identifier, machine_name Unix timestamp of the last publish attempt
healthcheck_status gauge check, description, system_identifier, machine_name Status of an individual health check entry (0/1/2)
healthcheck_duration_seconds gauge check, description, system_identifier, machine_name Duration of an individual health check entry

Requirements

  • .NET 8.0 or higher
  • The prometheus-net.AspNetCore package (or equivalent), wired up in the consuming application, to actually expose the registry via a /metrics endpoint

Documentation

For complete documentation, please visit the official documentation.

Contributing

Contributions are welcome! Please read the Contributing Guidelines before submitting a pull request.

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ by the NetEvolve Team Visit us at https://www.daily-devops.net for more information about our services and solutions.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.0 47 7/27/2026