53. Metrics

Spring Boot Actuator provides dependency management and auto-configuration for Micrometer, an application metrics facade that supports numerous monitoring systems:

Micrometer provides a separate module for each supported monitoring system. Depending on one (or more) of these modules is sufficient to get started with Micrometer in your Spring Boot application. To learn more about Micrometer’s capabilities, please refer to its reference documentation.

53.1 Spring MVC Metrics

Auto-configuration enables the instrumentation of requests handled by Spring MVC. When spring.metrics.web.server.auto-time-requests is true, this instrumentation occurs for all requests. Alternatively, when set to false, you can enable instrumentation by adding @Timed to a request-handling method.

By default, metrics are generated with the name, http.server.requests. The name can be customized by setting the spring.metrics.web.server.requests-metrics-name property.

53.1.1 Spring MVC Metric Tags

By default, Spring MVC-related metrics are tagged with the following information:

  • The request’s method.
  • The request’s URI (templated if possible).
  • The simple class name of any exception that was thrown while handling the request.
  • The response’s status.

To customize the tags, provide a @Bean that implements WebMvcTagsProvider.

53.2 WebFlux Metrics

Auto-configuration enables the instrumentation of all requests handled by WebFlux controllers. You can also use a helper class, RouterFunctionMetrics, to instrument applications that use WebFlux’s functional programming model.

By default, metrics are generated with the name http.server.requests. You can customize the name by setting the spring.metrics.web.server.requests-metrics-name property.

53.2.1 WebFlux Metric Tags

By default, WebFlux-related metrics for the annotation-based programming model are tagged with the following information:

  • The request’s method.
  • The request’s URI (templated if possible).
  • The simple class name of any exception that was thrown while handling the request.
  • The response’s status.

To customize the tags, provide a @Bean that implements WebFluxTagsProvider.

By default, metrics for the functional programming model are tagged with the following information:

  • The request’s method
  • The request’s URI (templated if possible).
  • The esponse’s status.

To customize the tags, use the defaultTags method on your RouterFunctionMetrics instance.

53.3 RestTemplate Metrics

Auto-configuration customizes the auto-configured RestTemplate to enable the instrumentation of its requests. MetricsRestTemplateCustomizer can be used to customize your own RestTemplate instances.

By default, metrics are generated with the name, http.client.requests. The name can be customized by setting the spring.metrics.web.client.requests-metrics-name property.

53.3.1 RestTemplate Metric Tags

By default, metrics generated by an instrumented RestTemplate are tagged with the following information:

  • The request’s method.
  • The request’s URI (templated if possible).
  • The response’s status.
  • The request URI’s host.

53.4 DataSource metrics

Auto-configuration will enable the instrumentation of all available DataSources with a metric named data.source. Data source instrumentation results in gauges representing the currently active, maximum allowed, and minimum allowed connections in the pool. Each of these gauges has a name which is prefixed by data.source by default. The prefix can be customized by using the spring.metrics.jdbc.datasource-metric-name property.

Metrics will also be tagged by the name of the DataSource computed based on the bean name.

53.5 Spring Integration Metrics

Auto-configuration enables binding of a number of Spring Integration-related metrics:

Table 53.1. General metrics

MetricDescription

spring.integration.channelNames

Number of Spring Integration channels

spring.integration.handlerNames

Number of Spring Integration handlers

spring.integration.sourceNames

Number of Spring Integration sources


Table 53.2. Channel metrics

MetricDescription

spring.integration.channel.receives

Number of receives

spring.integration.channel.sendErrors

Number of failed sends

spring.integration.channel.sends

Number of successful sends


Table 53.3. Handler metrics

MetricDescription

spring.integration.handler.duration.max

Maximum handler duration in milliseconds

spring.integration.handler.duration.min

Minimum handler duration in milliseconds

spring.integration.handler.duration.mean

Mean handler duration in milliseconds

spring.integration.handler.activeCount

Number of active handlers


Table 53.4. Source metrics

MetricDescription

spring.integration.source.messages

Number of successful source calls