Adding a Prometheus endpoint to .NET projects

The prometheus-net NuGet package provides a set of default metric collectors and a MetricServer class that provides the instrumentation endpoint that Prometheus hooks into. This package is great for adding Prometheus support to any app, the metrics are provided by a self-hosted HTTP endpoint, and you can record provide custom metrics for your application.

In the dockeronwindows/ch11-api-with-metrics image, I've added Prometheus support into a Web API project. The code to configure and start the metrics endpoint is in the PrometheusServer class:

public static void Start(){  _Server = new MetricServer(50505, new IOnDemandCollector[] {      new DotNetStatsCollector(), new PerfCounterCollector()    });

Get Docker on Windows now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.