Spring Boot has no single class named Metrics that does the monitoring for you. Application metrics come from Micrometer, which Spring Boot Actuator auto-configures: you inject a MeterRegistry (or use the static io.micrometer.core.instrument.Metrics helper) to create counters, gauges, timers and other meters, and Actuator exposes them to monitoring systems.
The name "Metrics class" usually refers to one of three things: the MeterRegistry bean, the static Metrics facade in Micrometer, or the older Spring Boot 1.x CounterService and GaugeService, which were removed in Spring Boot 2.0.
Micrometer is the vendor-neutral metrics facade used by Spring Boot 2.x, 3.x and later. It plays the role that SLF4J plays for logging: your code records measurements against one API, and a registry implementation sends them to Prometheus, Datadog, OpenTelemetry, CloudWatch or another backend.
| Name | What it is | When to use it |
|---|---|---|
MeterRegistry | Interface that creates and stores meters | Inject it into Spring beans (preferred) |
io.micrometer.core.instrument.Metrics | Static facade holding a global composite registry | Code that is not managed by Spring |
CounterService, GaugeService | Spring Boot 1.x classes | Removed in Spring Boot 2.0, do not use |
Spring Boot registers a MeterRegistry bean automatically when spring-boot-starter-actuator is on the classpath, plus one registry per backend dependency you add.
Add the Actuator starter and the registry for your monitoring system. This example uses Prometheus:
Then expose the endpoints in application.properties:
After you start the application, /actuator/metrics lists every meter name and /actuator/prometheus serves them in the Prometheus text format. The management.metrics.tags.* properties add common tags to every meter, which keeps dashboards filterable by service.
Inject MeterRegistry through the constructor and build meters once, not on every request.
Counter only goes up, which suits event counts. Timer records both the number of calls and the total time, so a backend can derive rates and latency percentiles.
A Gauge reports a value that can go up or down, such as a queue size. Micrometer holds only a weak reference to the observed object, so keep a strong reference elsewhere.
For methods you can also use @Timed and @Counted. They only take effect when the TimedAspect and CountedAspect beans are registered and Spring AOP is on the classpath:
DistributionSummary is the equivalent of Timer for non-time values such as payload sizes.
Spring Boot binds many meters without any code: JVM memory, garbage collection, threads, CPU, http.server.requests, HikariCP pool usage, Tomcat sessions, logback event counts and more. Read one with:
The static Metrics class is a convenience for code outside the Spring container, such as a library or a static utility:
It writes to a global composite registry. Spring Boot adds its registries to that global registry, so these meters still reach your backend. Inside Spring beans, inject MeterRegistry instead, because it is easier to test and keeps the dependency explicit.
Tags create one time series per unique value. Never tag with unbounded values such as user IDs, email addresses or full URLs, because high cardinality can overload your monitoring backend.
For tests, use SimpleMeterRegistry and assert on the meter:
Not in Spring Boot itself. The closest match is io.micrometer.core.instrument.Metrics, a static helper in Micrometer, while the main API is the MeterRegistry bean.
Micrometer replaced them in Spring Boot 2.0. Use Counter, Gauge and Timer built from a MeterRegistry.
Meters appear once they are registered, so a lazily created meter shows up after its first use. Also confirm metrics is in management.endpoints.web.exposure.include.
@Timed is quick for whole methods but needs the aspect bean. Use the Timer API when you need dynamic tags or to time only part of a method.
Spring Boot monitors applications through Micrometer, not a dedicated Metrics class. Add Actuator and a registry dependency, inject MeterRegistry to create counters, gauges and timers, and expose them through /actuator/metrics or a backend endpoint. Use the static Metrics facade only outside Spring, and keep tag values low-cardinality.