Middleware and Extension classes to allow instrumentation of all http requests to a given URL path.
The middleware intercepts all http requests made to an endpoint adds a timer and gauge showing the duration and number of currently in progress requests, writing these to the default Metrics Registry.
It uses the /api path to indicate that the endpoint is one belonging to the application that should have these metrics added.
Presuming you're using an application that are built with ASP.NET Core...
- Create the two classes
- Add the required NuGet package -> prometheus-net.AspNetCore
- In your startup class, in the Configure method add
app.UseMetricServer(); //Enables Prometheus metric gathering and enpoint at /metrics see https://github.com/prometheus-net/prometheus-net#
app.UseMetricsMiddleware(); // Uses the Middleware to wrap requets