Search in sources :

Example 1 with DataStore

use of org.apache.dubbo.common.store.DataStore in project dubbo by alibaba.

the class MetricsFilter method getThreadPoolMessage.

private List<MetricObject> getThreadPoolMessage() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(EXECUTOR_SERVICE_COMPONENT_KEY);
    List<MetricObject> threadPoolMetricList = new ArrayList<>();
    for (Map.Entry<String, Object> entry : executors.entrySet()) {
        ExecutorService executor = (ExecutorService) entry.getValue();
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            threadPoolMetricList.add(value2MetricObject("threadPool.active", tp.getActiveCount(), MetricLevel.MAJOR));
            threadPoolMetricList.add(value2MetricObject("threadPool.core", tp.getCorePoolSize(), MetricLevel.MAJOR));
            threadPoolMetricList.add(value2MetricObject("threadPool.max", tp.getMaximumPoolSize(), MetricLevel.MAJOR));
            threadPoolMetricList.add(value2MetricObject("threadPool.current", tp.getPoolSize(), MetricLevel.MAJOR));
        }
    }
    return threadPoolMetricList;
}
Also used : DataStore(org.apache.dubbo.common.store.DataStore) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) MetricObject(com.alibaba.metrics.common.MetricObject) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) MetricObject(com.alibaba.metrics.common.MetricObject) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 2 with DataStore

use of org.apache.dubbo.common.store.DataStore in project dubbo by alibaba.

the class ThreadPoolStatusCheckerTest method mockThreadPoolExecutor.

private void mockThreadPoolExecutor(int activeCount, int maximumPoolSize, String portKey) {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    ThreadPoolExecutor executor = Mockito.mock(ThreadPoolExecutor.class);
    Mockito.when(executor.getActiveCount()).thenReturn(activeCount);
    Mockito.when(executor.getMaximumPoolSize()).thenReturn(maximumPoolSize);
    dataStore.put(CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY, portKey, executor);
}
Also used : DataStore(org.apache.dubbo.common.store.DataStore) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with DataStore

use of org.apache.dubbo.common.store.DataStore in project dubbo by alibaba.

the class ThreadPoolStatusChecker method check.

@Override
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY);
    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for (Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();
        if (executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if (!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:").append(lvl).append(", max:").append(tp.getMaximumPoolSize()).append(", core:").append(tp.getCorePoolSize()).append(", largest:").append(tp.getLargestPoolSize()).append(", active:").append(tp.getActiveCount()).append(", task:").append(tp.getTaskCount()).append(", service port: ").append(port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
Also used : Status(org.apache.dubbo.common.status.Status) DataStore(org.apache.dubbo.common.store.DataStore) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Map(java.util.Map)

Example 4 with DataStore

use of org.apache.dubbo.common.store.DataStore in project dubbo by alibaba.

the class ThreadPoolStatusCheckerTest method destroy.

private void destroy(String portKey) {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.remove(CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY, portKey);
}
Also used : DataStore(org.apache.dubbo.common.store.DataStore)

Aggregations

DataStore (org.apache.dubbo.common.store.DataStore)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 MetricObject (com.alibaba.metrics.common.MetricObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 Status (org.apache.dubbo.common.status.Status)1