Search code examples
spring-bootspring-boot-actuatorspring-micrometer

How to enable ExecutorServiceMetrics in SpringBoot 2.1.2?


How to enable ExecutorServiceMetrics listed here ?

https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm/ExecutorServiceMetrics.java

SpringBoot version: 2.1.2.RELEASE

Under /actuator/metrics I can see jvm and some other outofbox auto configured metrics, but not executor metrics.

I have tried setting this, but no luck.

management:
  metrics:
    enable.executor: true

any help is appreciated.


Solution

  • I was able to get ExecutorServiceMetrics reporting metrics in a Spring Boot 2.1.2.RELEASE app and didn't have to do any more than create a monitored ExecutorService bean. I didn't have to add anything to my application.yml or application.properties to make this work.

    Example:

    @Configuration
    public class ExecutorConfig {
    
        @Bean
        public ExecutorService executorService(final MeterRegistry registry) {
            return ExecutorServiceMetrics.monitor(registry, Executors.newFixedThreadPool(20), "my executor", Tags.of("key", "value"));
        }
    }
    

    Then, just wire your executorService bean into your components and submit tasks to that executorService bean.