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 will enable the instrumentation of requests handled by Spring MVC. When metrics.web.server.auto-time-requests is true, this instrumentation will occur for all requests. Alternatively, when set to false, instrumentation can be enabled by adding @Timed to a request-handling method.

Metrics will, by default, be generated with the name http.server.requests. The name can be customized using the metrics.web.server.requests-metrics-name property.

53.1.1 Spring MVC metric tags

Spring MVC-related metrics will, by default, be tagged with the following:

  • Request’s method,
  • Request’s URI (templated if possible)
  • Simple class name of any exception that was thrown while handling the request
  • Response’s status

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

53.2 WebFlux metrics

Auto-configuration will enable the instrumentation of all requests handled by WebFlux controllers. A helper class, RouterFunctionMetrics, is also provided that can be used to instrument applications using WebFlux’s funtional programming model.

Metrics will, by default, be generated with the name http.server.requests. The name can be customized using the metrics.web.server.requests-metrics-name property.

53.2.1 WebFlux metric tags

WebFlux-related metrics for the annotation-based programming model will, by default, be tagged with the following:

  • Request’s method,
  • Request’s URI (templated if possible)
  • Simple class name of any exception that was thrown while handling the request
  • Response’s status

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

Metrics for the functional programming model will, by default, be tagged with the following:

  • Request’s method,
  • Request’s URI (templated if possible)
  • Response’s status

To customize the tags, use the defaultTags method on the RouterFunctionMetrics instance that you are using.

53.3 RestTemplate metrics

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

Metrics will, by default, be generated with the name http.client.requests. The name can be customized using the metrics.web.client.requests-metrics-name property.

53.3.1 RestTemplate metric tags

Metrics generated by an instrumeted RestTemplate will, by default, be tagged with the following:

  • Request’s method
  • Request’s URI (templated if possible)
  • Response’s status
  • Request URI’s host

Auto-configuration will enable 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