You configure metrics for monitoring a Spring Boot application by adding Spring Boot Actuator, which brings in Micrometer, and then exposing the metrics endpoint or a monitoring-system registry such as Prometheus. Actuator publishes JVM, CPU, HTTP server, datasource and logging metrics automatically, and you add custom metrics through the MeterRegistry.
A typical production setup is Actuator plus micrometer-registry-prometheus, scraped by Prometheus and charted in Grafana. This applies to Spring Boot 3.x, which uses Micrometer 1.x and supports Micrometer Observation for combined metrics and tracing.
Add the Actuator starter and the registry for your monitoring backend. Prometheus is shown here.
Micrometer is a facade, similar to SLF4J for logging. Other registries exist for Datadog, New Relic, InfluxDB, OTLP and more, and you can have several at once. Spring Boot configures each one from management.<system>.metrics.export.* properties.
By default only the health endpoint is exposed over HTTP. Expose the ones you need:
Then check the result:
The /actuator/metrics endpoint lists metric names and shows one metric at a time. The /actuator/prometheus endpoint returns every metric in the Prometheus text format. Common tags set by management.metrics.tags.* are added to every metric, which makes dashboards filterable by application and environment.
For production, serve Actuator on a separate management port and secure it:
| Area | Example metric names |
|---|---|
| JVM memory and GC | jvm.memory.used, jvm.gc.pause, jvm.threads.live |
| CPU and uptime | process.cpu.usage, system.cpu.usage, process.uptime |
| HTTP server | http.server.requests (count, time, tagged by method, uri, status, outcome) |
| Datasource pool | hikaricp.connections.active, hikaricp.connections.pending |
| Logging | logback.events (count by level) |
| Cache, Tomcat, Kafka and others | cache.gets, tomcat.sessions.active.current |
To get percentiles and histogram buckets for request latency, enable them with properties:
Prefer histogram buckets over client-side percentiles, because buckets can be aggregated across instances in Prometheus.
Inject MeterRegistry and register counters, timers and gauges. Keep tag values low-cardinality, such as a payment method, and never use user IDs or order IDs as tags.
In Prometheus the counter appears as shop_orders_placed_total, the timer as shop_payment_duration_seconds_* and the gauge as shop_carts_open. A gauge reports a value that goes up and down, so hold a strong reference to the object it reads, as the AtomicInteger does here.
Micrometer provides @Timed and @Counted. They require the TimedAspect or CountedAspect beans and spring-boot-starter-aop on the classpath.
Point Prometheus at the endpoint:
Useful starting queries in PromQL:
Alert on error rate, p95 latency, heap usage and connection pool saturation rather than on raw counts.
Actuator provides production endpoints such as health and metrics. Micrometer is the metrics library that records measurements and exports them to a monitoring system. Actuator wires Micrometer into Spring Boot.
The prometheus endpoint is not exposed or the micrometer-registry-prometheus dependency is missing. Add the dependency and include prometheus in management.endpoints.web.exposure.include.
No. Expose only what you need and protect the rest with Spring Security or a private management port. Endpoints such as env, heapdump and loggers can leak or change sensitive information.
Do not put unbounded values such as IDs, emails or raw URLs in tags. Each unique tag combination creates a new time series, which can overload the monitoring system.
Add spring-boot-starter-actuator and a Micrometer registry, expose only the endpoints you need, and add common tags for application and environment. Rely on the built-in JVM, HTTP and pool metrics, add counters, timers and gauges through MeterRegistry for business events, keep tags low-cardinality, and secure the management endpoints.