use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class StatusPageHandler method handle.
public Page handle(URL url) {
List<List<String>> rows = new ArrayList<List<String>>();
Set<String> names = ExtensionLoader.getExtensionLoader(StatusChecker.class).getSupportedExtensions();
Map<String, Status> statuses = new HashMap<String, Status>();
for (String name : names) {
StatusChecker checker = ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension(name);
List<String> row = new ArrayList<String>();
row.add(name);
Status status = checker.check();
if (status != null && !Status.Level.UNKNOWN.equals(status.getLevel())) {
statuses.put(name, status);
row.add(getLevelHtml(status.getLevel()));
row.add(status.getMessage());
rows.add(row);
}
}
Status status = StatusUtils.getSummaryStatus(statuses);
if ("status".equals(url.getPath())) {
return new Page("", "", "", status.getLevel().toString());
} else {
List<String> row = new ArrayList<String>();
row.add("summary");
row.add(getLevelHtml(status.getLevel()));
row.add("<a href=\"/status\" target=\"_blank\">summary</a>");
rows.add(row);
return new Page("Status (<a href=\"/status\" target=\"_blank\">summary</a>)", "Status", new String[] { "Name", "Status", "Description" }, rows);
}
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class StatusTelnetHandler method telnet.
public String telnet(Channel channel, String message) {
if (message.equals("-l")) {
List<StatusChecker> checkers = extensionLoader.getActivateExtension(channel.getUrl(), "status");
String[] header = new String[] { "resource", "status", "message" };
List<List<String>> table = new ArrayList<List<String>>();
Map<String, Status> statuses = new HashMap<String, Status>();
if (checkers != null && checkers.size() > 0) {
for (StatusChecker checker : checkers) {
String name = extensionLoader.getExtensionName(checker);
Status stat;
try {
stat = checker.check();
} catch (Throwable t) {
stat = new Status(Status.Level.ERROR, t.getMessage());
}
statuses.put(name, stat);
if (stat.getLevel() != null && stat.getLevel() != Status.Level.UNKNOWN) {
List<String> row = new ArrayList<String>();
row.add(name);
row.add(String.valueOf(stat.getLevel()));
row.add(stat.getMessage() == null ? "" : stat.getMessage());
table.add(row);
}
}
}
Status stat = StatusUtils.getSummaryStatus(statuses);
List<String> row = new ArrayList<String>();
row.add("summary");
row.add(String.valueOf(stat.getLevel()));
row.add(stat.getMessage());
table.add(row);
return TelnetUtils.toTable(header, table);
} else if (message.length() > 0) {
return "Unsupported parameter " + message + " for status.";
}
String status = channel.getUrl().getParameter("status");
Map<String, Status> statuses = new HashMap<String, Status>();
if (status != null && status.length() > 0) {
String[] ss = Constants.COMMA_SPLIT_PATTERN.split(status);
for (String s : ss) {
StatusChecker handler = extensionLoader.getExtension(s);
Status stat;
try {
stat = handler.check();
} catch (Throwable t) {
stat = new Status(Status.Level.ERROR, t.getMessage());
}
statuses.put(s, stat);
}
}
Status stat = StatusUtils.getSummaryStatus(statuses);
return String.valueOf(stat.getLevel());
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class ServerStatusChecker method check.
public Status check() {
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
if (servers == null || servers.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (ExchangeServer server : servers) {
if (!server.isBound()) {
level = Status.Level.ERROR;
buf.setLength(0);
buf.append(server.getLocalAddress());
break;
}
if (buf.length() > 0) {
buf.append(",");
}
buf.append(server.getLocalAddress());
buf.append("(clients:");
buf.append(server.getChannels().size());
buf.append(")");
}
return new Status(level, buf.toString());
}
use of com.alibaba.dubbo.common.status.Status 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());
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class LoadStatusChecker method check.
public Status check() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double load;
try {
Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
} catch (Throwable e) {
load = -1;
}
int cpu = operatingSystemMXBean.getAvailableProcessors();
return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
Aggregations