Search in sources :

Example 6 with Status

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);
    }
}
Also used : Status(com.alibaba.dubbo.common.status.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.alibaba.dubbo.container.page.Page) StatusChecker(com.alibaba.dubbo.common.status.StatusChecker)

Example 7 with Status

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());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StatusChecker(com.alibaba.dubbo.common.status.StatusChecker)

Example 8 with Status

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());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Example 9 with Status

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

Example 10 with Status

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);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Aggregations

Status (com.alibaba.dubbo.common.status.Status)14 Method (java.lang.reflect.Method)4 Map (java.util.Map)4 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)3 Connection (java.sql.Connection)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Level (com.alibaba.dubbo.common.status.Status.Level)2 StatusChecker (com.alibaba.dubbo.common.status.StatusChecker)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DataStore (com.alibaba.dubbo.common.store.DataStore)1 Page (com.alibaba.dubbo.container.page.Page)1 Registry (com.alibaba.dubbo.registry.Registry)1 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1