|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
|
|
|
|
|
package cn.hippo4j.core.springboot.starter.monitor;
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
|
|
|
|
|
import cn.hippo4j.common.config.ApplicationContextHolder;
|
|
|
|
|
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
|
|
|
|
|
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
|
|
|
|
@ -45,6 +46,8 @@ public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor {
|
|
|
|
|
|
|
|
|
|
private final Map<String, ThreadPoolRunStateInfo> RUN_STATE_CACHE = Maps.newConcurrentMap();
|
|
|
|
|
|
|
|
|
|
private final Map<String, ThreadPoolAdapterState> ADAPTER_STATE_CACHE = Maps.newConcurrentMap();
|
|
|
|
|
|
|
|
|
|
public MetricMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) {
|
|
|
|
|
super(threadPoolRunStateHandler);
|
|
|
|
|
}
|
|
|
|
@ -82,6 +85,34 @@ public class MetricMonitorHandler extends AbstractDynamicThreadPoolMonitor {
|
|
|
|
|
Metrics.gauge(metricName("reject.count"), tags, poolRunStateInfo, ThreadPoolRunStateInfo::getRejectCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void execute(ThreadPoolAdapterState poolAdapterState) {
|
|
|
|
|
ThreadPoolAdapterState stateInfo = ADAPTER_STATE_CACHE.get(poolAdapterState.getThreadPoolKey());
|
|
|
|
|
if (stateInfo == null) {
|
|
|
|
|
ADAPTER_STATE_CACHE.put(poolAdapterState.getThreadPoolKey(), poolAdapterState);
|
|
|
|
|
} else {
|
|
|
|
|
BeanUtil.copyProperties(poolAdapterState, stateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Environment environment = ApplicationContextHolder.getInstance().getEnvironment();
|
|
|
|
|
String applicationName = environment.getProperty("spring.application.name", "application");
|
|
|
|
|
Iterable<Tag> tags = Lists.newArrayList(
|
|
|
|
|
Tag.of(DYNAMIC_THREAD_POOL_ID_TAG, poolAdapterState.getThreadPoolKey()),
|
|
|
|
|
Tag.of(APPLICATION_NAME_TAG, applicationName));
|
|
|
|
|
|
|
|
|
|
// thread pool
|
|
|
|
|
Metrics.gauge(metricName("core.size"), tags, poolAdapterState, ThreadPoolAdapterState::getCoreSize);
|
|
|
|
|
Metrics.gauge(metricName("maximum.size"), tags, poolAdapterState, ThreadPoolAdapterState::getMaximumSize);
|
|
|
|
|
Metrics.gauge(metricName("current.size"), tags, poolAdapterState, ThreadPoolAdapterState::getPoolSize);
|
|
|
|
|
Metrics.gauge(metricName("active.size"), tags, poolAdapterState, ThreadPoolAdapterState::getActiveSize);
|
|
|
|
|
// queue
|
|
|
|
|
Metrics.gauge(metricName("queue.capacity"), tags, poolAdapterState, ThreadPoolAdapterState::getBlockingQueueCapacity);
|
|
|
|
|
Metrics.gauge(metricName("queue.size"), tags, poolAdapterState, ThreadPoolAdapterState::getQueueSize);
|
|
|
|
|
Metrics.gauge(metricName("queue.remaining.capacity"), tags, poolAdapterState, ThreadPoolAdapterState::getRemainingCapacity);
|
|
|
|
|
// other
|
|
|
|
|
Metrics.gauge(metricName("completed.task.count"), tags, poolAdapterState, ThreadPoolAdapterState::getCompletedTaskCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String metricName(String name) {
|
|
|
|
|
return String.join(".", METRIC_NAME_PREFIX, name);
|
|
|
|
|
}
|
|
|
|
|