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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay