What meters does Spring Boot auto-configure out of the box, and what is a MeterBinder?
answer
- actuator + micrometer => free meters
- MeterBinder.bindTo(registry)
- jvm.memory / jvm.gc / jvm.threads / system.cpu / process
- http.server.requests Timer
- hikaricp + logback.events
basics
~20 sWith Actuator + Micrometer on the classpath, Boot auto-registers meters for JVM memory/GC/threads, CPU, process, HTTP requests, datasource, and logback events. A MeterBinder is a small class that binds one such set of metrics to the MeterRegistry.
solid answer
~30 sAdding spring-boot-starter-actuator (which pulls in micrometer-core) makes Boot auto-configure a broad set of meters without any code. Core groups: jvm.memory.used/max/committed, jvm.gc.*, jvm.threads.*, system.cpu.usage and process.cpu.usage, process.uptime/start.time, http.server.requests (a Timer per endpoint), and — when present — http.client.requests, hikaricp.*/jdbc datasource pool metrics, and logback.events (log lines by level). Each group is produced by a MeterBinder — an interface with bindTo(MeterRegistry) — such as JvmMemoryMetrics, JvmGcMetrics, ProcessorMetrics, LogbackMetrics. Boot registers every MeterBinder bean it finds against the registry. You expose them at /actuator/metrics and /actuator/prometheus. So a MeterBinder is the plug-in unit that knows how to register a related family of gauges/counters/timers.
code
java · 19 lines// The MeterBinder contract (Micrometer)
public interface MeterBinder {
void bindTo(MeterRegistry registry);
}
// A built-in binder Boot registers for you:
// io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics
// io.micrometer.core.instrument.binder.system.ProcessorMetrics
// io.micrometer.core.instrument.binder.logging.LogbackMetrics
// Any MeterBinder @Bean is auto-bound to the primary MeterRegistry:
@Configuration
class MetricsConfig {
@Bean
MeterBinder queueSize(WorkQueue queue) {
return registry -> Gauge.builder("app.queue.size", queue, WorkQueue::size)
.register(registry);
}
}go deeper
Know that actuator gives free JVM/HTTP/process metrics and that MeterBinder registers a family of meters.
Name the concrete binder classes and the meter names/types each produces.
Explain conditional registration and how a MeterBinder bean is auto-bound to the registry.
Frame built-ins as covering RED/USE signals and decide what custom instrumentation is still needed on top.
## The big picture Spring Boot's Actuator, combined with **Micrometer** (a vendor-neutral metrics facade, think 'SLF4J for metrics'), gives you a large catalog of production metrics for free. You add one dependency — `spring-boot-starter-actuator` — and Boot's `MetricsAutoConfiguration` / `*MetricsAutoConfiguration` classes register meters against a `MeterRegistry` bean. ### Key terms - **Meter**: a single metric. Micrometer meter types: `Counter` (monotonic count), `Gauge` (instantaneous value that can go up/down, e.g. memory used), `Timer` (count + total time + max of timed events), `DistributionSummary`, `LongTaskTimer`, `FunctionCounter`/`FunctionTimer`. - **MeterRegistry**: the collection all meters are registered into and the thing a monitoring backend reads from (e.g. `PrometheusMeterRegistry`). - **MeterBinder**: a functional-ish interface `interface MeterBinder { void bindTo(MeterRegistry registry); }`. It packages the logic to create and register a *related family* of meters. Boot auto-detects every `MeterBinder` bean in the context and calls `bindTo` on the primary registry via `MeterRegistryPostProcessor`. ### What Boot auto-registers (the built-ins) Provided by Micrometer's `io.micrometer.core.instrument.binder.*` classes, enabled by Boot auto-config: - **JVM**: `JvmMemoryMetrics` -> `jvm.memory.used/committed/max` (tagged by `area`=heap/nonheap and memory pool `id`); `JvmGcMetrics` -> `jvm.gc.pause` timer, `jvm.gc.memory.allocated/promoted`; `JvmThreadMetrics` -> `jvm.threads.live/daemon/peak/states`; `ClassLoaderMetrics` -> `jvm.classes.loaded`. - **System/Process**: `ProcessorMetrics` -> `system.cpu.usage`, `process.cpu.usage`, `system.cpu.count`, `system.load.average.1m`; `UptimeMetrics` -> `process.uptime`, `process.start.time`; `FileDescriptorMetrics` -> `process.files.open/max`. - **HTTP server**: `http.server.requests` — a `Timer` recorded per request by a Servlet `Filter`/WebFlux `WebFilter` (`ServerHttpObservationFilter` in modern Boot), tagged with `uri`, `method`, `status`, `outcome`, `exception`. - **HTTP client**: `http.client.requests` for `RestTemplate`/`RestClient`/`WebClient` instrumented by Boot. - **DataSource/pool**: `DataSourcePoolMetrics` -> `jdbc.connections.*`; if HikariCP is the pool, `hikaricp.connections.*` (active/idle/pending/timeout/usage/acquire). - **Logging**: `LogbackMetrics` -> `logback.events` counter tagged by `level` (error/warn/info/...). - **Tomcat/Jetty**: `TomcatMetrics` -> `tomcat.*` when the container manager is available. ### How to see them `management.endpoints.web.exposure.include=metrics,prometheus`. Then `GET /actuator/metrics` lists names, `GET /actuator/metrics/jvm.memory.used` drills into one, `GET /actuator/prometheus` gives the scrape format. ### Gotchas - Some binders only register when their dependency/condition is present (HikariCP metrics need HikariCP; `http.client.requests` needs an instrumented client). - Metrics are lazily/eagerly created but a Timer like `http.server.requests` only shows tag values that have actually been observed. ### When to rely on them Almost always — they cover the standard RED/USE signals (request rate/errors/duration + resource saturation) with zero code, which is exactly what you want before adding custom business metrics.
- Which single dependency turns most of these on, and how do you view them?spring-boot-starter-actuator (it brings micrometer-core). View via /actuator/metrics, drill into one with /actuator/metrics/{name}, or scrape /actuator/prometheus after exposing the endpoint.
- Are all built-in meters always registered?No — many are conditional. hikaricp.* needs HikariCP as the pool, http.client.requests needs an instrumented RestTemplate/WebClient, TomcatMetrics needs the Tomcat manager. JVM/process/CPU/logback ones are effectively always on.
saying these in an interview costs you the question
- Thinking you must write code to get JVM/HTTP metrics
- Believing http.server.requests is a Gauge or Counter rather than a Timer
- Assuming MeterBinder is a Spring annotation rather than a Micrometer interface