Search in sources :

Example 6 with ThreadPoolStats

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;
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool)

Example 7 with ThreadPoolStats

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;
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats)

Example 8 with ThreadPoolStats

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;
}
Also used : lombok.val(lombok.val) ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 9 with 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);
    }
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) DtpProperties(com.dtp.common.config.DtpProperties) WebServerTpHandler(com.dtp.adapter.web.handler.WebServerTpHandler)

Example 10 with ThreadPoolStats

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()));
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats)

Aggregations

ThreadPoolStats (com.dtp.common.dto.ThreadPoolStats)10 DtpExecutor (com.dtp.core.thread.DtpExecutor)2 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)2 ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)2 WebServerTpHandler (com.dtp.adapter.web.handler.WebServerTpHandler)1 DtpProperties (com.dtp.common.config.DtpProperties)1 JettyThreadPool (com.dtp.common.config.web.JettyThreadPool)1 ExecutorWrapper (com.dtp.core.support.ExecutorWrapper)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 lombok.val (lombok.val)1