a. Overview

Main Goal

The main goal of this hands-on is to add observability to the microservices stack using Prometheus for metrics collection and Grafana for visualization, enabling real-time monitoring of the entire platform.

Observability is a critical property of distributed systems. Without it, understanding system behavior, diagnosing failures, and measuring performance across multiple services becomes nearly impossible. The three pillars of observability are:

  • Logging: Structured records of events occurring within each service.
  • Monitoring: Continuous collection and visualization of system and application metrics over time.
  • Tracing: Tracking the end-to-end lifecycle of a single request as it flows through multiple services.

In this hands-on, we will focus on monitoring, wiring together Spring Boot Actuator, Prometheus, and Grafana.

The resulting architecture adds a dedicated observability layer alongside the existing microservices:

flowchart LR
    subgraph obs [Observability Layer]
        prometheus@{ shape: cyl, label: "Prometheus\n:9090" }
        grafana[Grafana\n:3000]
        prometheus --> grafana
    end
    subgraph api [Trusted Layer]
        loadbalancer --> gateway
        gateway --> auth
        gateway --> account
    end
    prometheus e1@-.->|scrape /actuator/prometheus| gateway
    prometheus e2@-.->|scrape /actuator/prometheus| auth
    prometheus e3@-.->|scrape /actuator/prometheus| account
    internet e0@==>|:80| loadbalancer
    e0@{ animate: true }
    e1@{ animate: true }
    e2@{ animate: true }
    e3@{ animate: true }

The setup requires changes across three areas:

  • b. Microservices


    Add Actuator and Prometheus registry dependencies to each Spring Boot service and expose the metrics endpoint.

  • c. Docker Compose


    Add Prometheus and Grafana services to the docker compose.yaml file, ensuring they are on the same network as the microservices.

  • d. Prometheus


    Deploy Prometheus via Docker Compose and configure it to scrape metrics from each microservice.

  • e. Grafana


    Deploy Grafana via Docker Compose, connect it to Prometheus, and explore pre-built dashboards.

  • f. Run


    Rebuild and start the full stack using Docker Compose, then verify that all services are running and metrics are being scraped.