Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example projects with Prometheus in ASP.NET Core MVC?

I want to monitor my ASP.NET Core MVC application with Prometheus. Following the instructions on https://github.com/prometheus-net/prometheus-net I managed to expose some metrics from my application as desired.

I have no previous experience using Prometheus and I am new to C# and ASP.NET Core MCV in general. Therefore I was interested in studying example projects.

Searching the web I've only managed to find minor code snippets, but nothing close to complete. Could someone guide me to example projects of this kind?

Some questions that I am interested in include

  • How to expose the /metric endpoint? Using a dedicated MetricController or simply by adding the app.UseMetricServer() in Startup.cs as the Github project page suggests?
  • Is it best-practice to use a dedicated port for the /metric endpoint? If so, how do you expose this port? (UseMetricServer does not seem to accept a port)
  • What is the best way to add your metrics? E.g. if I want to count the number of calls made to a specific endpoint in my app, should one simply add the count logic in the controller for that particular route? Or is there a better way of doing it?
like image 695
zelphus Avatar asked Jul 18 '18 12:07

zelphus


1 Answers

I wrote some examples here: https://github.com/PrometheusClientNet/Prometheus.Client.Examples

But, I use my own fork: https://github.com/PrometheusClientNet/Prometheus.Client.

You can adapt for original library or you can use mine.

Your questions:

  • Here is your choice. I prefer use Middleware(https://github.com/PrometheusClientNet/Prometheus.Client.AspNetCore) for Web and MetricServer(https://github.com/PrometheusClientNet/Prometheus.Client.MetricServer) for Console

  • Best way, use /metrics the same port as the application. If this is not possible, then I need details

  • You can use my library: https://github.com/PrometheusClientNet/Prometheus.Client.HttpRequestDurations. Or just grab code from my repository.

like image 115
Serge K Avatar answered Sep 25 '22 02:09

Serge K