Supported Metrics and Meters
Spring Boot provides automatic meter registration for a wide variety of technologies. In most situations, the defaults provide sensible metrics that can be published to any of the supported monitoring systems.
JVM Metrics
Auto-configuration enables JVM Metrics by using core Micrometer classes.
JVM metrics are published under the jvm.
meter name.
The following JVM metrics are provided:
-
Various memory and buffer pool details
-
Statistics related to garbage collection
-
Thread utilization
-
The number of classes loaded and unloaded
-
JVM version information
-
JIT compilation time
System Metrics
Auto-configuration enables system metrics by using core Micrometer classes.
System metrics are published under the system.
, process.
, and disk.
meter names.
The following system metrics are provided:
-
CPU metrics
-
File descriptor metrics
-
Uptime metrics (both the amount of time the application has been running and a fixed gauge of the absolute start time)
-
Disk space available
Application Startup Metrics
Auto-configuration exposes application startup time metrics:
-
application.started.time
: time taken to start the application. -
application.ready.time
: time taken for the application to be ready to service requests.
Metrics are tagged by the fully qualified name of the application class.
Logger Metrics
Auto-configuration enables the event metrics for both Logback and Log4J2.
The details are published under the log4j2.events.
or logback.events.
meter names.
Task Execution and Scheduling Metrics
Auto-configuration enables the instrumentation of all available ThreadPoolTaskExecutor
and ThreadPoolTaskScheduler
beans, as long as the underling ThreadPoolExecutor
is available.
Metrics are tagged by the name of the executor, which is derived from the bean name.
Spring MVC Metrics
Auto-configuration enables the instrumentation of all requests handled by Spring MVC controllers and functional handlers.
By default, metrics are generated with the name, http.server.requests
.
You can customize the name by setting the management.observations.http.server.requests.name
property.
To add to the default tags, provide a @Bean
that extends DefaultServerRequestObservationConvention
from the org.springframework.http.server.observation
package.
To replace the default tags, provide a @Bean
that implements ServerRequestObservationConvention
.
In some cases, exceptions handled in web controllers are not recorded as request metrics tags. Applications can opt in and record exceptions by setting handled exceptions as request attributes. |
By default, all requests are handled.
To customize the filter, provide a @Bean
that implements FilterRegistrationBean<WebMvcMetricsFilter>
.
Spring WebFlux Metrics
Auto-configuration enables the instrumentation of all requests handled by Spring WebFlux controllers and functional handlers.
By default, metrics are generated with the name, http.server.requests
.
You can customize the name by setting the management.observations.http.server.requests.name
property.
To add to the default tags, provide a @Bean
that extends DefaultServerRequestObservationConvention
from the org.springframework.http.server.reactive.observation
package.
To replace the default tags, provide a @Bean
that implements ServerRequestObservationConvention
.
In some cases, exceptions handled in controllers and handler functions are not recorded as request metrics tags. Applications can opt in and record exceptions by setting handled exceptions as request attributes. |
Jersey Server Metrics
Auto-configuration enables the instrumentation of all requests handled by the Jersey JAX-RS implementation.
By default, metrics are generated with the name, http.server.requests
.
You can customize the name by setting the management.observations.http.server.requests.name
property.
By default, Jersey server metrics are tagged with the following information:
Tag | Description |
---|---|
|
The simple class name of any exception that was thrown while handling the request. |
|
The request’s method (for example, |
|
The request’s outcome, based on the status code of the response.
1xx is |
|
The response’s HTTP status code (for example, |
|
The request’s URI template prior to variable substitution, if possible (for example, |
To customize the tags, provide a @Bean
that implements JerseyTagsProvider
.
HTTP Client Metrics
Spring Boot Actuator manages the instrumentation of both RestTemplate
and WebClient
.
For that, you have to inject the auto-configured builder and use it to create instances:
-
RestTemplateBuilder
forRestTemplate
-
WebClient.Builder
forWebClient
You can also manually apply the customizers responsible for this instrumentation, namely ObservationRestTemplateCustomizer
and ObservationWebClientCustomizer
.
By default, metrics are generated with the name, http.client.requests
.
You can customize the name by setting the management.observations.http.client.requests.name
property.
To customize the tags when using RestTemplate
, provide a @Bean
that implements ClientRequestObservationConvention
from the org.springframework.http.client.observation
package.
To customize the tags when using WebClient
, provide a @Bean
that implements ClientRequestObservationConvention
from the org.springframework.web.reactive.function.client
package.
Tomcat Metrics
Auto-configuration enables the instrumentation of Tomcat only when an MBeanRegistry
is enabled.
By default, the MBeanRegistry
is disabled, but you can enable it by setting server.tomcat.mbeanregistry.enabled
to true
.
Tomcat metrics are published under the tomcat.
meter name.
Cache Metrics
Auto-configuration enables the instrumentation of all available Cache
instances on startup, with metrics prefixed with cache
.
Cache instrumentation is standardized for a basic set of metrics.
Additional, cache-specific metrics are also available.
The following cache libraries are supported:
-
Cache2k
-
Caffeine
-
Hazelcast
-
Any compliant JCache (JSR-107) implementation
-
Redis
Metrics are tagged by the name of the cache and by the name of the CacheManager
, which is derived from the bean name.
Only caches that are configured on startup are bound to the registry.
For caches not defined in the cache’s configuration, such as caches created on the fly or programmatically after the startup phase, an explicit registration is required.
A CacheMetricsRegistrar bean is made available to make that process easier.
|
DataSource Metrics
Auto-configuration enables the instrumentation of all available DataSource
objects with metrics prefixed with jdbc.connections
.
Data source instrumentation results in gauges that represent the currently active, idle, maximum allowed, and minimum allowed connections in the pool.
Metrics are also tagged by the name of the DataSource
computed based on the bean name.
By default, Spring Boot provides metadata for all supported data sources.
You can add additional DataSourcePoolMetadataProvider beans if your favorite data source is not supported.
See DataSourcePoolMetadataProvidersConfiguration for examples.
|
Also, Hikari-specific metrics are exposed with a hikaricp
prefix.
Each metric is tagged by the name of the pool (you can control it with spring.datasource.name
).
Hibernate Metrics
If org.hibernate.orm:hibernate-micrometer
is on the classpath, all available Hibernate EntityManagerFactory
instances that have statistics enabled are instrumented with a metric named hibernate
.
Metrics are also tagged by the name of the EntityManagerFactory
, which is derived from the bean name.
To enable statistics, the standard JPA property hibernate.generate_statistics
must be set to true
.
You can enable that on the auto-configured EntityManagerFactory
:
-
Properties
-
YAML
spring.jpa.properties[hibernate.generate_statistics]=true
spring:
jpa:
properties:
"[hibernate.generate_statistics]": true
Spring Data Repository Metrics
Auto-configuration enables the instrumentation of all Spring Data Repository
method invocations.
By default, metrics are generated with the name, spring.data.repository.invocations
.
You can customize the name by setting the management.metrics.data.repository.metric-name
property.
The @Timed
annotation from the io.micrometer.core.annotation
package is supported on Repository
interfaces and methods.
If you do not want to record metrics for all Repository
invocations, you can set management.metrics.data.repository.autotime.enabled
to false
and exclusively use @Timed
annotations instead.
A @Timed annotation with longTask = true enables a long task timer for the method.
Long task timers require a separate metric name and can be stacked with a short task timer.
|
By default, repository invocation related metrics are tagged with the following information:
Tag | Description |
---|---|
|
The simple class name of the source |
|
The name of the |
|
The result state ( |
|
The simple class name of any exception that was thrown from the invocation. |
To replace the default tags, provide a @Bean
that implements RepositoryTagsProvider
.
RabbitMQ Metrics
Auto-configuration enables the instrumentation of all available RabbitMQ connection factories with a metric named rabbitmq
.
Spring Integration Metrics
Spring Integration automatically provides Micrometer support whenever a MeterRegistry
bean is available.
Metrics are published under the spring.integration.
meter name.
Kafka Metrics
Auto-configuration registers a MicrometerConsumerListener
and MicrometerProducerListener
for the auto-configured consumer factory and producer factory, respectively.
It also registers a KafkaStreamsMicrometerListener
for StreamsBuilderFactoryBean
.
For more detail, see the Micrometer Native Metrics section of the Spring Kafka documentation.
MongoDB Metrics
This section briefly describes the available metrics for MongoDB.
MongoDB Command Metrics
Auto-configuration registers a MongoMetricsCommandListener
with the auto-configured MongoClient
.
A timer metric named mongodb.driver.commands
is created for each command issued to the underlying MongoDB driver.
Each metric is tagged with the following information by default:
Tag | Description |
---|---|
|
The name of the command issued. |
|
The identifier of the cluster to which the command was sent. |
|
The address of the server to which the command was sent. |
|
The outcome of the command ( |
To replace the default metric tags, define a MongoCommandTagsProvider
bean, as the following example shows:
-
Java
-
Kotlin
import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class MyCommandTagsProviderConfiguration {
@Bean
public MongoCommandTagsProvider customCommandTagsProvider() {
return new CustomCommandTagsProvider();
}
}
import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false)
class MyCommandTagsProviderConfiguration {
@Bean
fun customCommandTagsProvider(): MongoCommandTagsProvider? {
return CustomCommandTagsProvider()
}
}
To disable the auto-configured command metrics, set the following property:
-
Properties
-
YAML
management.metrics.mongo.command.enabled=false
management:
metrics:
mongo:
command:
enabled: false
MongoDB Connection Pool Metrics
Auto-configuration registers a MongoMetricsConnectionPoolListener
with the auto-configured MongoClient
.
The following gauge metrics are created for the connection pool:
-
mongodb.driver.pool.size
reports the current size of the connection pool, including idle and and in-use members. -
mongodb.driver.pool.checkedout
reports the count of connections that are currently in use. -
mongodb.driver.pool.waitqueuesize
reports the current size of the wait queue for a connection from the pool.
Each metric is tagged with the following information by default:
Tag | Description |
---|---|
|
The identifier of the cluster to which the connection pool corresponds. |
|
The address of the server to which the connection pool corresponds. |
To replace the default metric tags, define a MongoConnectionPoolTagsProvider
bean:
-
Java
-
Kotlin
import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class MyConnectionPoolTagsProviderConfiguration {
@Bean
public MongoConnectionPoolTagsProvider customConnectionPoolTagsProvider() {
return new CustomConnectionPoolTagsProvider();
}
}
import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false)
class MyConnectionPoolTagsProviderConfiguration {
@Bean
fun customConnectionPoolTagsProvider(): MongoConnectionPoolTagsProvider {
return CustomConnectionPoolTagsProvider()
}
}
To disable the auto-configured connection pool metrics, set the following property:
-
Properties
-
YAML
management.metrics.mongo.connectionpool.enabled=false
management:
metrics:
mongo:
connectionpool:
enabled: false
Jetty Metrics
Auto-configuration binds metrics for Jetty’s ThreadPool
by using Micrometer’s JettyServerThreadPoolMetrics
.
Metrics for Jetty’s Connector
instances are bound by using Micrometer’s JettyConnectionMetrics
and, when server.ssl.enabled
is set to true
, Micrometer’s JettySslHandshakeMetrics
.
@Timed Annotation Support
To use @Timed
where it is not directly supported by Spring Boot, refer to the Micrometer documentation.
Redis Metrics
Auto-configuration registers a MicrometerCommandLatencyRecorder
for the auto-configured LettuceConnectionFactory
.
For more detail, see the Micrometer Metrics section of the Lettuce documentation.