Java Code Examples for com.alibaba.dubbo.common.status.Status#Level

The following examples show how to use com.alibaba.dubbo.common.status.Status#Level . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerStatusChecker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: RegistryStatusChecker.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public Status check() {
    Collection<Registry> registries = AbstractRegistryFactory.getRegistries();
    if (registries.isEmpty()) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Registry registry : registries) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(registry.getUrl().getAddress());
        if (!registry.isAvailable()) {
            level = Status.Level.ERROR;
            buf.append("(disconnected)");
        } else {
            buf.append("(connected)");
        }
    }
    return new Status(level, buf.toString());
}
 
Example 3
Source File: ServerStatusChecker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 4
Source File: ServerStatusChecker.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 5
Source File: RegistryStatusChecker.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public Status check() {
    Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries();
    if (regsitries == null || regsitries.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Registry registry : regsitries) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(registry.getUrl().getAddress());
        if (! registry.isAvailable()) {
            level = Status.Level.ERROR;
            buf.append("(disconnected)");
        } else {
            buf.append("(connected)");
        }
    }
    return new Status(level, buf.toString());
}
 
Example 6
Source File: RegistryStatusChecker.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public Status check() {
    Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries();
    if (regsitries == null || regsitries.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Registry registry : regsitries) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(registry.getUrl().getAddress());
        if (! registry.isAvailable()) {
            level = Status.Level.ERROR;
            buf.append("(disconnected)");
        } else {
            buf.append("(connected)");
        }
    }
    return new Status(level, buf.toString());
}
 
Example 7
Source File: RegistryStatusChecker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Status check() {
    Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries();
    if (regsitries == null || regsitries.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Registry registry : regsitries) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(registry.getUrl().getAddress());
        if (! registry.isAvailable()) {
            level = Status.Level.ERROR;
            buf.append("(disconnected)");
        } else {
            buf.append("(connected)");
        }
    }
    return new Status(level, buf.toString());
}
 
Example 8
Source File: RegistryStatusChecker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Status check() {
    Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries();
    if (regsitries == null || regsitries.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Registry registry : regsitries) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(registry.getUrl().getAddress());
        if (! registry.isAvailable()) {
            level = Status.Level.ERROR;
            buf.append("(disconnected)");
        } else {
            buf.append("(connected)");
        }
    }
    return new Status(level, buf.toString());
}
 
Example 9
Source File: ThreadPoolStatusChecker.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
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());
}
 
Example 10
Source File: StatusPageHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getLevelColor(Status.Level level) {
    if (level == Status.Level.OK) {
        return "green";
    } else if (level == Status.Level.ERROR) {
        return "red";
    } else if (level == Status.Level.WARN) {
        return "yellow";
    }
    return "gray";
}
 
Example 11
Source File: ThreadPoolStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 12
Source File: ThreadPoolStatusChecker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 13
Source File: ThreadPoolStatusChecker.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 14
Source File: StatusPageHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getLevelColor(Status.Level level) {
    if (level == Status.Level.OK) {
        return "green";
    } else if (level == Status.Level.ERROR) {
        return "red";
    } else if (level == Status.Level.WARN) {
        return "yellow";
    }
    return "gray";
}
 
Example 15
Source File: DataSourceStatusChecker.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Status check() {
    ApplicationContext context = ServiceBean.getSpringContext();
    if (context == null) {
        return new Status(Status.Level.UNKNOWN);
    }
    Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
    if (dataSources == null || dataSources.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
        DataSource dataSource = entry.getValue();
        if (buf.length() > 0) {
            buf.append(", ");
        }
        buf.append(entry.getKey());
        try {
            try (Connection connection = dataSource.getConnection()) {
                DatabaseMetaData metaData = connection.getMetaData();
                try (ResultSet resultSet = metaData.getTypeInfo()) {
                    if (!resultSet.next()) {
                        level = Status.Level.ERROR;
                    }
                }
                buf.append(metaData.getURL());
                buf.append("(");
                buf.append(metaData.getDatabaseProductName());
                buf.append("-");
                buf.append(metaData.getDatabaseProductVersion());
                buf.append(")");
            }
        } catch (Throwable e) {
            logger.warn(e.getMessage(), e);
            return new Status(level, e.getMessage());
        }
    }
    return new Status(level, buf.toString());
}
 
Example 16
Source File: StatusPageHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String getLevelColor(Status.Level level) {
    if (level == Status.Level.OK) {
        return "green";
    } else if (level == Status.Level.ERROR) {
        return "red";
    } else if (level == Status.Level.WARN) {
        return "yellow";
    }
    return "gray";
}
 
Example 17
Source File: StatusPageHandler.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
private String getLevelHtml(Status.Level level) {
    return "<font color=\"" + getLevelColor(level) + "\">" + level.name() + "</font>";
}
 
Example 18
Source File: DataSourceStatusChecker.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Status check() {
    ApplicationContext context = ServiceBean.getSpringContext();
    if (context == null) {
        return new Status(Status.Level.UNKNOWN);
    }
    Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
    if (dataSources == null || dataSources.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
        DataSource dataSource = entry.getValue();
        if (buf.length() > 0) {
            buf.append(", ");
        }
        buf.append(entry.getKey());
        try {
            Connection connection = dataSource.getConnection();
            try {
                DatabaseMetaData metaData = connection.getMetaData();
                ResultSet resultSet = metaData.getTypeInfo();
                try {
                    if (! resultSet.next()) {
                        level = Status.Level.ERROR;
                    }
                } finally {
                    resultSet.close();
                }
                buf.append(metaData.getURL());
                buf.append("(");
                buf.append(metaData.getDatabaseProductName());
                buf.append("-");
                buf.append(metaData.getDatabaseProductVersion());
                buf.append(")");
            } finally {
                connection.close();
            }
        } catch (Throwable e) {
            logger.warn(e.getMessage(), e);
            return new Status(level, e.getMessage());
        }
    }
    return new Status(level, buf.toString());
}
 
Example 19
Source File: StatusPageHandler.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private String getLevelHtml(Status.Level level) {
    return "<font color=\"" + getLevelColor(level) + "\">" + level.name() + "</font>";
}
 
Example 20
Source File: DataSourceStatusChecker.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Status check() {
    ApplicationContext context = ServiceBean.getSpringContext();
    if (context == null) {
        return new Status(Status.Level.UNKNOWN);
    }
    Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
    if (dataSources == null || dataSources.size() == 0) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
        DataSource dataSource = entry.getValue();
        if (buf.length() > 0) {
            buf.append(", ");
        }
        buf.append(entry.getKey());
        try {
            Connection connection = dataSource.getConnection();
            try {
                DatabaseMetaData metaData = connection.getMetaData();
                ResultSet resultSet = metaData.getTypeInfo();
                try {
                    if (!resultSet.next()) {
                        level = Status.Level.ERROR;
                    }
                } finally {
                    resultSet.close();
                }
                buf.append(metaData.getURL());
                buf.append("(");
                buf.append(metaData.getDatabaseProductName());
                buf.append("-");
                buf.append(metaData.getDatabaseProductVersion());
                buf.append(")");
            } finally {
                connection.close();
            }
        } catch (Throwable e) {
            logger.warn(e.getMessage(), e);
            return new Status(level, e.getMessage());
        }
    }
    return new Status(level, buf.toString());
}