Search in sources :

Example 1 with ThreadPoolStats

use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by lyh200.

the class JettyTpHandler method getPoolStats.

@Override
public ThreadPoolStats getPoolStats() {
    ThreadPool.SizedThreadPool threadPool = convertAndGet();
    ThreadPoolStats poolStats = ThreadPoolStats.builder().corePoolSize(threadPool.getMinThreads()).maximumPoolSize(threadPool.getMaxThreads()).dtpName("jettyWebServerTp").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) JettyThreadPool(com.dtp.common.config.web.JettyThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool)

Example 2 with ThreadPoolStats

use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by lyh200.

the class DtpMonitor method run.

private void run() {
    List<String> names = DtpRegistry.listAllDtpNames();
    if (CollUtil.isEmpty(names)) {
        return;
    }
    names.forEach(x -> {
        DtpExecutor executor = DtpRegistry.getExecutor(x);
        AlarmManager.triggerAlarm(() -> doAlarm(executor, ALARM_TYPES));
        ThreadPoolStats poolStats = MetricsConverter.convert(executor);
        doCollect(poolStats);
    });
    publishEvent();
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) DtpExecutor(com.dtp.core.thread.DtpExecutor)

Example 3 with ThreadPoolStats

use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.

the class MetricsConverter method convert.

public static ThreadPoolStats convert(ExecutorWrapper wrapper) {
    if (wrapper.getExecutor() == null) {
        return null;
    }
    ThreadPoolStats poolStats = convertCommon(wrapper.getExecutor());
    poolStats.setPoolName(wrapper.getThreadPoolName());
    poolStats.setDynamic(false);
    return poolStats;
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats)

Example 4 with ThreadPoolStats

use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.

the class DtpMonitor method run.

private void run() {
    List<String> dtpNames = DtpRegistry.listAllDtpNames();
    List<String> commonNames = DtpRegistry.listAllCommonNames();
    if (CollUtil.isEmpty(dtpNames) && CollUtil.isEmpty(commonNames)) {
        return;
    }
    boolean enabledCollect = dtpProperties.isEnabledCollect();
    dtpNames.forEach(x -> {
        DtpExecutor executor = DtpRegistry.getDtpExecutor(x);
        AlarmManager.triggerAlarm(() -> doAlarm(executor, ALARM_TYPES));
        if (enabledCollect) {
            ThreadPoolStats poolStats = MetricsConverter.convert(executor);
            doCollect(poolStats);
        }
    });
    if (!enabledCollect) {
        return;
    }
    commonNames.forEach(x -> {
        ExecutorWrapper wrapper = DtpRegistry.getCommonExecutor(x);
        ThreadPoolStats poolStats = MetricsConverter.convert(wrapper);
        doCollect(poolStats);
    });
    publishEvent();
}
Also used : ThreadPoolStats(com.dtp.common.dto.ThreadPoolStats) DtpExecutor(com.dtp.core.thread.DtpExecutor) ExecutorWrapper(com.dtp.core.support.ExecutorWrapper)

Example 5 with ThreadPoolStats

use of com.dtp.common.dto.ThreadPoolStats in project dynamic-tp by dromara.

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.getPoolName());
    if (Objects.isNull(oldStats)) {
        GAUGE_CACHE.put(threadPoolStats.getPoolName(), threadPoolStats);
    } else {
        BeanUtil.copyProperties(threadPoolStats, oldStats);
    }
    gauge(GAUGE_CACHE.get(threadPoolStats.getPoolName()));
}
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