Monitoring .NET Applications with Prometheus
Professional
You can instrument your .NET application with prometheus-net and let the Glouton agent scrape its /metrics endpoint.
Install the client library
Section titled “Install the client library”dotnet add package prometheus-net.AspNetCoreMinimal example
Section titled “Minimal example”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");Scrape with Glouton
Section titled “Scrape with Glouton”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.