use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.
the class JettyDtpHandler method getPoolStats.
@Override
public ThreadPoolStats getPoolStats() {
ThreadPool.SizedThreadPool threadPool = convertAndGet();
ThreadPoolStats poolStats = ThreadPoolStats.builder().corePoolSize(threadPool.getMinThreads()).maximumPoolSize(threadPool.getMaxThreads()).poolName(POOL_NAME).build();
if (threadPool instanceof QueuedThreadPool) {
QueuedThreadPool queuedThreadPool = (QueuedThreadPool) threadPool;
poolStats.setActiveCount(queuedThreadPool.getBusyThreads());
poolStats.setQueueSize(queuedThreadPool.getQueueSize());
poolStats.setPoolSize(queuedThreadPool.getThreads());
}
return poolStats;
}
use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.
the class MetricsConverter method convert.
public static ThreadPoolStats convert(DtpExecutor executor) {
if (executor == null) {
return null;
}
ThreadPoolStats poolStats = convertCommon(executor);
poolStats.setPoolName(executor.getThreadPoolName());
poolStats.setRejectHandlerName(executor.getRejectHandlerName());
poolStats.setRejectCount(executor.getRejectCount());
poolStats.setRunTimeoutCount(executor.getRunTimeoutCount());
poolStats.setQueueTimeoutCount(executor.getQueueTimeoutCount());
poolStats.setDynamic(true);
return poolStats;
}
use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.
the class AbstractDtpHandler method getMultiPoolStats.
/**
* Get multi thread pool stats.
*
* @return thead pools stats
*/
@Override
public List<ThreadPoolStats> getMultiPoolStats() {
val executors = getExecutors();
if (CollUtil.isEmpty(executors)) {
return Collections.emptyList();
}
List<ThreadPoolStats> threadPoolStats = Lists.newArrayList();
executors.forEach((k, v) -> {
val e = (ThreadPoolExecutor) v;
val stats = ThreadPoolStats.builder().corePoolSize(e.getCorePoolSize()).maximumPoolSize(e.getMaximumPoolSize()).queueType(e.getQueue().getClass().getSimpleName()).queueCapacity(e.getQueue().size() + e.getQueue().remainingCapacity()).queueSize(e.getQueue().size()).queueRemainingCapacity(e.getQueue().remainingCapacity()).activeCount(e.getActiveCount()).taskCount(e.getTaskCount()).completedTaskCount(e.getCompletedTaskCount()).largestPoolSize(e.getLargestPoolSize()).poolSize(e.getPoolSize()).waitTaskCount(e.getQueue().size()).poolName(k).build();
threadPoolStats.add(stats);
});
return threadPoolStats;
}
use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by lyh200.
the class DtpWebCollectListener method onApplicationEvent.
@Override
public void onApplicationEvent(CollectEvent event) {
DtpProperties dtpProperties = event.getDtpProperties();
if (!dtpProperties.isEnabledCollect()) {
return;
}
try {
WebServerTpHandler webServerTpHandler = ApplicationContextHolder.getBean(WebServerTpHandler.class);
ThreadPoolStats poolStats = webServerTpHandler.getPoolStats();
if (poolStats == null) {
return;
}
CollectorHandler.getInstance().collect(poolStats, dtpProperties.getCollectorType());
} catch (Exception e) {
log.error("DynamicTp monitor, collect web server thread pool metrics failed.", e);
}
}
use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by lyh200.
the class MicroMeterCollector method collect.
@Override
public void collect(ThreadPoolStats threadPoolStats) {
// metrics must be held with a strong reference, even though it is never referenced within this class
ThreadPoolStats oldStats = GAUGE_CACHE.get(threadPoolStats.getDtpName());
if (Objects.isNull(oldStats)) {
GAUGE_CACHE.put(threadPoolStats.getDtpName(), threadPoolStats);
} else {
BeanUtil.copyProperties(threadPoolStats, oldStats);
}
gauge(GAUGE_CACHE.get(threadPoolStats.getDtpName()));
}
Aggregations