Metrics for Spring microservices
Inventory, order and cart services registered with Eureka and configured from a Config Server, each exposing Micrometer metrics that Prometheus scrapes and Grafana charts.
- Type
- Personal project
- Year
- 2025
- Status
- Runs locally
- Stack
The problem
A small e-commerce-shaped system used to practise running several Spring services together and seeing what each of them is doing.
With six processes running, it is hard to tell which one is slow or down. The goal was one place to see request rates, latencies and JVM health for every service.
My role
Personal project. I wrote the services, the Prometheus scrape configuration and the Grafana dashboard.
Approach
Every service exposes the same Actuator metrics endpoint, so adding a service to monitoring is one scrape target rather than new code. Discovery and configuration are centralised the same way, through Eureka and the Config Server.
Architecture
Services pull configuration from the Config Server and register with Eureka at startup. Each exposes /actuator/prometheus; Prometheus scrapes them every 15 seconds and Grafana reads from Prometheus.
- api-gateway
- service-registry
- configserver
- inventory-service
- order-service
- cart-service
- Prometheus
- Grafana
Request flow
Technical decisions
- Eureka
- Services find each other by name, so ports can change without editing every caller.
- Spring Cloud Config
- Shared configuration in one place instead of copied into each service.
- Micrometer + Actuator
- Standard JVM and HTTP metrics with no custom instrumentation code.
- Prometheus
- Pull-based scraping: a service that stops responding shows up as a failed target, not silence.
- Grafana
- Dashboards kept as JSON next to the code they describe.
Implementation
Each service is its own Gradle project with the Actuator and the Micrometer Prometheus registry on the runtime classpath. Scrape targets and labels are declared in Prometheus/Prometheus.yml.
Prometheus and Grafana run in Docker Compose while the Spring services run on the host and are reached through host.docker.internal.
Challenges and solutions
Challenge
With six processes, it is hard to tell which one is slow or down.
Solution
Prometheus scrapes /actuator/prometheus on every service every 15 seconds and labels each series with the application name; one Grafana dashboard reads them all.
Challenge
Hard-coded ports break callers whenever a service moves.
Solution
Services register with Eureka at startup and find each other by name.
Challenge
Prometheus and Grafana run in Docker, while the services run on the host.
Solution
Scrape targets point at host.docker.internal, so the containers can reach the host processes.
Security and reliability
- Actuator endpoints are reachable without authentication. That is acceptable on a laptop; anywhere shared they belong on a separate management port or behind authentication.
- Grafana’s admin credentials are set in the Compose file and are for local use only.
Testing
Each service includes the generated context-load test. The monitoring configuration has no automated checks.
Trade-offs
Choice
Pull-based scraping every 15 seconds
What it costs
Values are sampled, so a short-lived change between two scrapes is not recorded, and Prometheus must be able to reach every service.
Choice
Services on the host, monitoring in Docker
What it costs
Fast to iterate on a service, but the system is not one reproducible Compose stack.
Choice
Metrics only
What it costs
A dashboard shows that something is slow, not which call in a request chain caused it.
Results
A compact, reproducible example of service discovery, central configuration and metrics collection across several Spring services.
Lessons and next steps
Known limitations
- The Compose file mounts ./prometheus/prometheus.yml, but the file is committed as Prometheus/Prometheus.yml. On case-sensitive file systems such as Linux the paths must match.
- Grafana’s runtime database and plugin files are committed alongside the dashboard JSON; only the JSON needs to be versioned.
- Images use the latest tag, so a fresh pull can change behaviour.
- Metrics only — no distributed tracing or log aggregation yet.
What I would change next
- Fix the case of the Prometheus configuration path so the stack runs on Linux.
- Version only the dashboard JSON, and pin image tags.
- Add distributed tracing so a slow request can be followed across services.
Next projectDevSecOps pipeline with Jenkins