Skip to content

Monitoring .NET Applications with Prometheus

Professional

You can instrument your .NET application with prometheus-net and let the Glouton agent scrape its /metrics endpoint.

Terminal window
dotnet add package prometheus-net.AspNetCore

The snippet below defines a counter and exposes it on http://localhost:8080/metrics using ASP.NET Core:

using Prometheus;
var requestsTotal = Metrics.CreateCounter(
"myapp_requests_total",
"Total number of processed requests.");
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () =>
{
requestsTotal.Inc();
return "Hello";
});
app.MapMetrics();
app.Run("http://0.0.0.0:8080");

Configure Glouton to scrape your application by adding the following to /etc/glouton/conf.d/50-prometheus-metrics.conf:

metric:
prometheus:
targets:
- url: "http://localhost:8080/metrics"
name: "my_dotnet_application"
allow_metrics:
- "myapp_requests_total"

Restart the agent to apply the configuration. See Prometheus Monitoring for the full list of options, including Docker label auto-discovery and Kubernetes annotations.