Adding Metrics to the Application

We will be using Prometheus to instrument our application to report metrics. Prometheus is quick to set up and just as quick to use.

Setting up the Prometheus endpoint for metrics collection

To begin, we need to set up an endpoint on the HTTP server so that Prometheus can fetch the metrics we will be publishing. Unlike OpenTelemetry, which uses a push model to send data to the collector, Prometheus uses a pull model and will need to be told where to look for metrics data.

To provide Prometheus with an endpoint to fetch the data, we need to import the promhttp package and then add the handler it provides to the HTTP server. We must modify the /internal/system/system.go file to add the endpoint:

Get hands-on with 1400+ tech skills courses.