功能特性
基于以上背景分析,我们对线程池 ThreadPoolExecutor 做一些扩展增强,主要实现以下目标
实现对运行中线程池参数的动态修改,实时生效
实时监控线程池的运行状态,触发设置的报警策略时报警,报警信息推送办公平台
定时采集线程池指标数据,配合像 Grafana 这种可视化监控平台做大盘监控
<!-- For dynamic-tp -->
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-cloud-starter-nacos</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-okhttp3</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-webserver</artifactId>
</dependency>
项目中引入 micrometer-prometheus 依赖,可实现 dynamic-tp
组件的指标采集
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
# HELP thread_pool_queue_size
# TYPE thread_pool_queue_size gauge
thread_pool_queue_size{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_queue_size{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_queue_size{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_core_size
# TYPE thread_pool_core_size gauge
thread_pool_core_size{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_core_size{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 6.0
thread_pool_core_size{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 100.0
# HELP thread_pool_current_size
# TYPE thread_pool_current_size gauge
thread_pool_current_size{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_current_size{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_current_size{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_queue_remaining_capacity
# TYPE thread_pool_queue_remaining_capacity gauge
thread_pool_queue_remaining_capacity{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_queue_remaining_capacity{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 200.0
thread_pool_queue_remaining_capacity{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 2.147483647E9
# HELP thread_pool_queue_capacity
# TYPE thread_pool_queue_capacity gauge
thread_pool_queue_capacity{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_queue_capacity{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 200.0
thread_pool_queue_capacity{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 2.147483647E9
# HELP thread_pool_queue_timeout_count
# TYPE thread_pool_queue_timeout_count gauge
thread_pool_queue_timeout_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_queue_timeout_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_queue_timeout_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_run_timeout_count
# TYPE thread_pool_run_timeout_count gauge
thread_pool_run_timeout_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_run_timeout_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_run_timeout_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_maximum_size
# TYPE thread_pool_maximum_size gauge
thread_pool_maximum_size{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 2.147483647E9
thread_pool_maximum_size{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 8.0
thread_pool_maximum_size{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 200.0
# HELP thread_pool_task_count
# TYPE thread_pool_task_count gauge
thread_pool_task_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_task_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_task_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_active_count
# TYPE thread_pool_active_count gauge
thread_pool_active_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_active_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_active_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_wait_task_count
# TYPE thread_pool_wait_task_count gauge
thread_pool_wait_task_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_wait_task_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_wait_task_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_reject_count
# TYPE thread_pool_reject_count gauge
thread_pool_reject_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} -1.0
thread_pool_reject_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_reject_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_completed_task_count
# TYPE thread_pool_completed_task_count gauge
thread_pool_completed_task_count{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_completed_task_count{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_completed_task_count{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
# HELP thread_pool_largest_size
# TYPE thread_pool_largest_size gauge
thread_pool_largest_size{app_name="app-test",application="app-test",thread_pool_name="okhttp3ClientTp",} 0.0
thread_pool_largest_size{app_name="app-test",application="app-test",thread_pool_name="dtpExecutor1",} 0.0
thread_pool_largest_size{app_name="app-test",application="app-test",thread_pool_name="undertowTp",} 0.0
作者:Jeebiz 创建时间:2023-05-05 14:19
最后编辑:Jeebiz 更新时间:2024-11-05 12:45
最后编辑:Jeebiz 更新时间:2024-11-05 12:45