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;
}
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);
}
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());
}
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);
}
Aggregations