DEV Community

Cover image for Example: API Metrics with Prometheus and Grafana
Robert Nemet
Robert Nemet

Posted on • Originally published at rnemet.dev

Example: API Metrics with Prometheus and Grafana

This post is a follow-up to the previous posts on designing metrics for event-driven systems. This humble post is a practical example of how to implement the metrics API and how to use it to create a dashboard in Grafana.
I'm not using Kubernetes but Docker Compose; the concepts are the same. The reason is simplicity.

The code is available on this GitHub repository.

The Scenario

The setup comprises two API services(app and beta) and a database(postgres). Liquibase creates the database schema.
API services are two instances of the same service. They connect to the same database.

They are calling each other via HTTP calls, like ping-pong. Then there is an echo endpoint that returns the request body and a counter endpoint that counts
the number of calls to the endpoint. The counter is stored in the database. Metrics are exposed on the /metrics endpoint.
Metrics are collected by Prometheus and displayed in Grafana.

In addition, a vegeta service sends requests to API services, like load testing.

The code is available on the same repository. It is done in Go. The code is not the focus of this post,
but I will show some snippets to give you an idea of how it is implemented.

If you are interested in this topic, continue to my blog.

Top comments (0)