Closed
Description
Micrometer allows to monitor the executor states using ExecutorServiceMetrics
It allows to monitor the usage of executors with metrics like:
"async.executor",
"async.executor.active",
"async.executor.completed",
"async.executor.idle",
"async.executor.pool.core",
"async.executor.pool.max",
"async.executor.pool.size",
"async.executor.queue.remaining",
"async.executor.queued",
To achieve that we have to wrap our executors with something like this:
/**
* <p>A default task executor.</p>
* <p>The {@link Executor} instance to be used when processing async
* method invocations.</p>
*/
@Bean(DEFAULT_TASK_EXECUTOR_BEAN_NAME)
@Override
public Executor getAsyncExecutor() {
// Using a thread-pooling TaskExecutor implementation,
// in particular for executing a large number of short-lived tasks.
final ThreadPoolTaskExecutor executor = new TaskExecutorBuilder()
.corePoolSize(100) // With unlimited queue
.allowCoreThreadTimeOut(true)
.threadNamePrefix("task-")
.build();
executor.initialize();
return ExecutorServiceMetrics.monitor(
meterRegistry,
executor.getThreadPoolExecutor(),
"AsyncExecutor",
"async",
tags);
}
(I am creating the tags from MetricsProperties#getTags
)
It might be great if an AutoConfiguration could do it magically (it's why we love Spring-Boot). Not sure how it could be implemented in a Spring-Boot way properly.
We can find such request in various places:
- https://stackoverflow.com/questions/56176852/how-to-enable-executorservicemetrics-in-springboot-2-1-2
- How to enable ExecutorServiceMetrics in SpringBoot 2 ? micrometer-metrics/micrometer#1430
cc @snicoll