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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.