Search in sources :

Example 1 with DataStore

use of com.alibaba.dubbo.common.store.DataStore in project dubbo by alibaba.

the class ThreadPoolStatusChecker method check.

public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.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 != null && 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:" + lvl + ", max:" + tp.getMaximumPoolSize() + ", core:" + tp.getCorePoolSize() + ", largest:" + tp.getLargestPoolSize() + ", active:" + tp.getActiveCount() + ", task:" + tp.getTaskCount() + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) DataStore(com.alibaba.dubbo.common.store.DataStore) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Map(java.util.Map)

Aggregations

Status (com.alibaba.dubbo.common.status.Status)1 DataStore (com.alibaba.dubbo.common.store.DataStore)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1