To integrate Spring Boot with Prometheus, add spring-boot-starter-actuator and micrometer-registry-prometheus, expose the prometheus endpoint, and point a Prometheus scrape job at /actuator/prometheus. Micrometer, the metrics facade behind Actuator, then publishes JVM, HTTP and custom metrics in the Prometheus text format.
This guide targets Spring Boot 3.x. Property names changed between Boot 2 and Boot 3, and copying old snippets is the most common reason the endpoint returns 404.
Maven:
Gradle:
Spring Boot manages the version of both artifacts, so you do not specify one. If you add the registry later to an existing app, restart it so auto-configuration picks it up.
By default only health is exposed over HTTP. Expose the Prometheus endpoint explicitly.
Notes on what changed from older tutorials:
management.metrics.export.prometheus.enabled. In Boot 3 it is management.prometheus.metrics.export.enabled, and it defaults to true when the registry is on the classpath, so you rarely need it.prometheus endpoint is enabled by default once it is exposed. You do not need management.endpoint.prometheus.enabled=true.application common tag lets you filter dashboards per service.Start the app and open http://localhost:8080/actuator/prometheus. You should see lines such as:
Metrics can reveal internals, so do not publish them to the internet. The simplest option is to serve Actuator on a separate port that only your network can reach.
If you use Spring Security, allow the Prometheus endpoint only from trusted callers.
Inject MeterRegistry to add business metrics next to the built-in ones.
Micrometer names use dots, and the Prometheus registry converts them: orders.created becomes orders_created_total, and the timer produces orders_checkout_seconds_count, _sum and _max. Keep tag values low-cardinality; a user ID or URL as a tag creates one time series per value and can overload Prometheus.
Create prometheus.yml:
Run Prometheus and Grafana with Docker Compose:
Open http://localhost:9090/targets and check that the job is UP. On Kubernetes you would use pod annotations or a ServiceMonitor instead of static targets.
http://localhost:3000.http://prometheus:9090 as the URL when both run in the same Compose network.Useful starting queries:
The histogram query works only because percentiles-histogram was enabled for http.server.requests above.
Usually the endpoint is not exposed or the registry dependency is missing. Check that management.endpoints.web.exposure.include contains prometheus and that micrometer-registry-prometheus is on the classpath.
Prometheus pulls (scrapes) by default. For short-lived jobs that exit before a scrape, use the Prometheus Pushgateway support in Micrometer.
Yes. Change management.endpoints.web.base-path for the path or management.server.port for the port, and update metrics_path and targets in the scrape config to match.
Micrometer is the instrumentation API inside your app; Prometheus is the system that stores and queries the data. Micrometer can export to many backends, with Prometheus being one registry.
Add Actuator and the Micrometer Prometheus registry, expose the prometheus endpoint, and scrape /actuator/prometheus. Use Boot 3 property names, restrict access to the management port, keep tag cardinality low, and build Grafana dashboards on the exported series.