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
<PackageReference Include="NetEvolve.HealthPublishers.Prometheus.Metrics" Version="1.10.0" />
<PackageVersion Include="NetEvolve.HealthPublishers.Prometheus.Metrics" Version="1.10.0" />
<PackageReference Include="NetEvolve.HealthPublishers.Prometheus.Metrics" />
paket add NetEvolve.HealthPublishers.Prometheus.Metrics --version 1.10.0
#r "nuget: NetEvolve.HealthPublishers.Prometheus.Metrics, 1.10.0"
#:package NetEvolve.HealthPublishers.Prometheus.Metrics@1.10.0
#addin nuget:?package=NetEvolve.HealthPublishers.Prometheus.Metrics&version=1.10.0
#tool nuget:?package=NetEvolve.HealthPublishers.Prometheus.Metrics&version=1.10.0
NetEvolve.HealthPublishers.Prometheus.Metrics
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
HealthStatusto a numeric gauge value using the enum's own ordinal (Unhealthy→0,Degraded→1,Healthy→2) - Labels every gauge with the machine name and a required, free-form
SystemIdentifierto 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.AspNetCorepackage (or equivalent), wired up in the consuming application, to actually expose the registry via a/metricsendpoint
Related Packages
- NetEvolve.HealthPublishers.Prometheus.PushGateway - Push-model counterpart, pushes the same set of metrics to a Prometheus Pushgateway instance over HTTP
- NetEvolve.HealthPublishers.Abstractions - Shared abstractions used by all
NetEvolve.HealthPublishers.*packages
Documentation
For complete documentation, please visit the official documentation.
Contributing
Contributions are welcome! Please read the Contributing Guidelines before submitting a pull request.
Support
- Issues: Report bugs or request features on GitHub Issues
- Documentation: Read the full documentation at https://github.com/dailydevops/healthpublishers
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 | Versions 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. |
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
- prometheus-net (>= 8.2.1)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
- prometheus-net (>= 8.2.1)
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
- prometheus-net (>= 8.2.1)
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 |