Add metrics support for ThreadPoolTaskExecutor and ThreadPoolTaskScheduler
See original GitHub issueMicrometer 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
- https://github.com/micrometer-metrics/micrometer/issues/1430
cc @snicoll
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Spring Metrics
Calling collectionSize on our meter registry adds a Gauge time series named population that changes when observed by a metrics backend or exporter....
Read more >Spring framework monitoring ThreadPoolTaskExecutor queue ...
If I use jmx to monnitor ThreadPoolTaskExecutor, how can I monitor queue size level to make sure it is healthy?
Read more >A Guide to the Spring Task Scheduler - Baeldung
A quick and practical guide to scheduling in Spring with Task Scheduler.
Read more >Spring Boot Actuator | SpringerLink
Add a dependency for the spring-boot-starter-actuator to your project and the health and metrics will be enabled and exposed for your ...
Read more >Index (spring-metrics 0.5.0.RELEASE API) - javadoc.io
Record metrics on the use of a ThreadPoolTaskExecutor . monitor(MeterRegistry, ThreadPoolTaskScheduler, String, Iterable<Tag>) - Static method in class ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve added a proposal in 910e14f. Unfortunately, it is too late for
2.5.xbut I’ll do my best to get that in for2.6.0-M1. It handles both task executors and task schedulers using Micrometer’sExecutorServiceMetrics.@aheritier yes, we’re not going to implement that feature this way. Spring Boot rather injects the component (i.e. thread pool) later on and register metrics on it, which avoids causing unnecessary early initialisations due to the dependency on the
MeterRegistry. If you have questions about registering custom metrics, please follow-up on StackOverflow or come chat with the community on Gitter.