ASP.NET Core Metrics with Prometheus
How to use solid metrics to know how your app performs in the wild
When it comes to running production software, you’ll hardly ever find yourself in a situation where you know too much about how your application is performing. More often than not, the opposite is true, and we don’t nearly have enough information available about our application’s performance in the wild.
Fortunately, there are a variety of free, open source tools available that provide time series databases and allow us to accrue and store all sorts of metrics. While individual metrics at an instant in time may not mean much on their own, having access to metrics over an extended period of time allows for in-depth trend analysis. One of the most commonly used tools for aggregating metrics is Prometheus.
Prometheus utilizes a pull model to obtain its metrics. That is, you point it at an URL exposed by your application, Prometheus grabs metrics from that URL every once in a while, and stores them. The power of this model is in its simplicity — the only thing your application needs to do is expect a metrics endpoint in a specific format, and let Prometheus deal with the rest.
Unfortunately, ASP.NET Core doesn’t come with a metrics endpoint by default — we’ll have to create one for ourselves. In this…