Micrometer Prometheus Observability in Spring Boot

In the era of microservices and cloud-native applications, observability is not optional β€” it’s essential. While logs and traces are common, metrics are the fastest way to understand the real-time state of your system. That’s where Micrometer and Prometheus shine.

This post dives deep into how to implement Micrometer Prometheus Observability in Spring Boot, enabling developers and DevOps teams to collect, monitor, and visualize metrics effectively. We’ll set up a complete pipeline from exposing metrics with Micrometer to scraping and visualizing them with Prometheus.

Micrometer Prometheus Observability in Spring Boot

πŸ“Š What is Observability?

Observability is the capability to understand the internal states of a system by examining the outputs. It’s composed of:

  • Metrics – quantitative data (e.g., request count, memory usage)
  • Logs – timestamped records of events
  • Traces – the flow of requests across services

In this post, we focus on metrics, leveraging Micrometer and Prometheus.

🧩 What is Micrometer?

Micrometer is a metrics facade in Spring Boot that provides a simple way to collect JVM, system, and application-level metrics. It supports multiple backends like:

  • Prometheus
  • New Relic
  • Datadog
  • Graphite
  • Elastic

Spring Boot Actuator integrates Micrometer out of the box to expose metrics endpoints.

πŸ“¦ What is Prometheus?

Prometheus is a time-series database designed for monitoring. It scrapes metrics exposed by applications and provides a powerful query language (PromQL) and integrates well with Grafana.

πŸ› οΈ Setting up Spring Boot with Micrometer and Prometheus

πŸ“ Maven Dependencies

βš™οΈ Application Configuration

application.yml

πŸ§ͺ Custom Metrics with Micrometer

This code registers a gauge and counter metric that Prometheus can scrape.

πŸ”— Exposing Metrics Endpoint

Once your application is running, you can access:

This endpoint will expose all JVM, system, and custom metrics.

πŸ“ˆ Prometheus Configuration

Create a file called prometheus.yml:

Use host.docker.internal if Prometheus runs in Docker and your app runs locally.

🐳 Running Prometheus with Docker

Visit http://localhost:9090 to access Prometheus UI.

πŸ” Querying Metrics in Prometheus

Try some PromQL queries:

  • custom_orders_active
  • custom_orders_completed_total
  • http_server_requests_seconds_count

You can now create alerts or forward these to Grafana for dashboards.

πŸ“Š Adding Grafana for Visualization (Optional)

Login to Grafana (admin/admin)

Add Prometheus as a data source

Import dashboard ID 4701 for Spring Boot metrics

🧼 Best Practices

  • Use tags (labels) wisely for fine-grained metrics
  • Avoid unbounded high-cardinality metrics
  • Monitor metrics like:
    • JVM memory
    • CPU usage
    • HTTP request latency
    • GC time
  • Combine with distributed tracing for full observability

πŸ”š Conclusion

Micrometer Prometheus Observability in Spring Boot provides a seamless way to monitor the performance, reliability, and health of your applications. By combining Spring Boot Actuator, Micrometer, Prometheus, and optionally Grafana, you get a powerful monitoring stack that’s production ready.

Whether you’re scaling microservices or improving SLAs, metrics play a critical role. Implement this observability pipeline today to build resilient, transparent systems.

πŸ”— External References