Spring Boot Actuator + Prometheus Metrics Setup
Fast recall
Quick revision
Core answer
micrometer-registry-prometheus dependency, enable the Prometheus Actuator endpoint in application.yml, and point your Prometheus scrape config at /actuator/prometheus.Hands-on knowledge of the Micrometer + Actuator + Prometheus integration pipeline.
Forgetting to expose the `prometheus` endpoint in `management.endpoints.web.exposure.include`, leaving it inaccessible.
Mention custom metrics using MeterRegistry and how to add common tags to all metrics for service-level filtering in Grafana.
Interview-ready guide
Interview answer
Spring Boot Actuator exposes application metrics over HTTP, and the Prometheus integration publishes those metrics in Prometheus's text format for scraping. The most common issue is that the Prometheus endpoint is hidden by default.
Setup
- Add
spring-boot-starter-actuatorandmicrometer-registry-prometheus; Actuator auto-configures the/actuator/prometheusendpoint that Prometheus scrapes - The endpoint is disabled by default: add
management.endpoints.web.exposure.include=health,info,prometheus,metricsto expose it; in production, restrict access to this endpoint to the Prometheus server's IP or put it on a separate management port
Configuring Prometheus scraping
- Add a scrape configuration in
prometheus.yml:- job_name: 'spring-boot' static_configs: - targets: ['myservice:8080']; Prometheus scrapes/actuator/prometheusat the configured interval (typically 15 or 60 seconds) - On Kubernetes, use a
ServiceMonitorCRD (if using the Prometheus Operator) to configure scraping declaratively — the ServiceMonitor watches for services with matching labels and auto-configures Prometheus to scrape them
What gets exposed automatically
- JVM metrics:
jvm.memory.used,jvm.gc.pause.count,jvm.threads.live,jvm.gc.memory.allocated - HTTP metrics:
http.server.requeststagged with URI, method, status, and outcome - HikariCP metrics:
hikaricp.connections.active,hikaricp.connections.pending— connection pool saturation is visible from the metrics endpoint without any custom code - System metrics: CPU usage, disk space, load average
Securing the Prometheus endpoint
- The
/actuator/prometheusendpoint contains detailed application internals — configure Spring Security to require authentication or restrict by IP; alternatively put it on a separatemanagement.server.portthat is not exposed to external traffic
Spring Boot Actuator + Prometheus Metrics Setup
Direct Answer
Add the micrometer-registry-prometheus dependency, enable the Prometheus Actuator endpoint in application.yml, and point your Prometheus scrape config at /actuator/prometheus.
Common Mistakes & Pitfalls
Forgetting to expose the prometheus endpoint in management.endpoints.web.exposure.include, leaving it inaccessible.
Check your understanding
Answer these without looking back at the article.
- How do you secure the `/actuator/prometheus` endpoint in production?
- What is the difference between a Counter and a Gauge in Micrometer?
- How would you expose custom business metrics alongside JVM metrics?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.