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

The following examples show how to use com.alibaba.dubbo.common.status.Status. These examples are extracted from open source projects. 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 Project: dubbo-2.6.5   Source File: LoadStatusChecker.java    License: Apache License 2.0 6 votes vote down vote up
@Override
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]);
        if (load == -1) {
            com.sun.management.OperatingSystemMXBean bean =
                    (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean;
            load = bean.getSystemCpuLoad();
        }
    } 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 < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: StatusUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if (!Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 3
Source Project: dubbo-2.6.5   Source File: RegistryStatusChecker.java    License: 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 4
Source Project: dubbox   Source File: StatusManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 5
Source Project: dubbox   Source File: RegistryStatusChecker.java    License: 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 Project: dubbox   Source File: RegistryStatusChecker.java    License: 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 Project: dubbox   Source File: ServerStatusChecker.java    License: 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 8
Source Project: dubbox   Source File: StatusUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 9
Source Project: dubbox   Source File: StatusManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 10
Source Project: dubbox   Source File: StatusManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 11
Source Project: dubbox-hystrix   Source File: StatusUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 12
Source Project: dubbox   Source File: ServerStatusChecker.java    License: 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 13
Source Project: dubbox-hystrix   Source File: StatusManager.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 14
Source Project: dubbo3   Source File: StatusUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Status getSummaryStatus(Map<String, Status> statuses) {
    Level level = Level.OK;
    StringBuilder msg = new StringBuilder();
    for (Map.Entry<String, Status> entry : statuses.entrySet()) {
        String key = entry.getKey();
        Status status = entry.getValue();
        Level l = status.getLevel();
        if (Level.ERROR.equals(l)) {
            level = Level.ERROR;
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        } else if (Level.WARN.equals(l)) {
            if(! Level.ERROR.equals(level)) {
                level = Level.WARN;
            }
            if (msg.length() > 0) {
                msg.append(",");
            }
            msg.append(key);
        }
    }
    return new Status(level, msg.toString());
}
 
Example 15
Source Project: dubbo3   Source File: ServerStatusChecker.java    License: 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 16
Source Project: dubbo-2.6.5   Source File: ThreadPoolStatusChecker.java    License: 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 17
Source Project: dubbo3   Source File: StatusManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 过滤不需要汇总页面的监控项
 */
public Map<String, Status> getStatusList(String[] excludes) {
    Map<String, Status> statuses = new HashMap<String, Status>();
    Map<String, StatusChecker> temp = new HashMap<String, StatusChecker>();
    temp.putAll(statusHandlers);
    if(excludes != null&&excludes.length>0){
        for(String exclude : excludes){
            temp.remove(exclude);
        }
    }
    for (Map.Entry<String, StatusChecker> entry : temp.entrySet()) {
            statuses.put(entry.getKey(), entry.getValue().check());
    }
    return statuses;
}
 
Example 18
Source Project: dubbox   Source File: LoadStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 19
Source Project: dubbox   Source File: DatabaseStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    boolean ok;
    try {
        Connection connection = dataSource.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet resultSet = metaData.getTypeInfo();
            try {
                ok = resultSet.next();
            } finally {
                resultSet.close();
            }
            if (message == null) {
                message = metaData.getURL()
                    + " (" + metaData.getDatabaseProductName() 
                    + " " + metaData.getDatabaseProductVersion()
                    + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
            }
            if (version == 0) {
                version = metaData.getDatabaseMajorVersion();
            }
        } finally {
            connection.close();
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        ok = false;
    }
    return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
 
Example 20
Source Project: dubbo3   Source File: MemoryStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    Runtime runtime = Runtime.getRuntime();
    long freeMemory = runtime.freeMemory();
    long totalMemory = runtime.totalMemory();
    long maxMemory = runtime.maxMemory();
    boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于2M报警
    String msg = "max:" + (maxMemory / 1024 / 1024) + "M,total:" 
    + (totalMemory / 1024 / 1024) + "M,used:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M,free:" + (freeMemory / 1024 / 1024) + "M";
    return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg);
}
 
Example 21
Source Project: dubbo-2.6.5   Source File: StatusUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSummaryStatus3() throws Exception {
    Status status1 = new Status(Status.Level.OK);
    Map<String, Status> statuses = new HashMap<String, Status>();
    statuses.put("status1", status1);
    Status status = StatusUtils.getSummaryStatus(statuses);
    assertThat(status.getLevel(), is(Status.Level.OK));
    assertThat(status.getMessage(), isEmptyOrNullString());
}
 
Example 22
Source Project: dubbox   Source File: DatabaseStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    boolean ok;
    try {
        Connection connection = dataSource.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet resultSet = metaData.getTypeInfo();
            try {
                ok = resultSet.next();
            } finally {
                resultSet.close();
            }
            if (message == null) {
                message = metaData.getURL()
                    + " (" + metaData.getDatabaseProductName() 
                    + " " + metaData.getDatabaseProductVersion()
                    + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
            }
            if (version == 0) {
                version = metaData.getDatabaseMajorVersion();
            }
        } finally {
            connection.close();
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        ok = false;
    }
    return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
 
Example 23
Source Project: dubbo-2.6.5   Source File: SpringStatusCheckerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithLifeCycleRunning() {
    ApplicationLifeCycle applicationLifeCycle = mock(ApplicationLifeCycle.class);
    new ServiceBean<Object>().setApplicationContext(applicationLifeCycle);
    given(applicationLifeCycle.getConfigLocations()).willReturn(new String[]{"test1", "test2"});
    given(applicationLifeCycle.isRunning()).willReturn(true);

    Status status = springStatusChecker.check();

    assertThat(status.getLevel(), is(Status.Level.OK));
    assertThat(status.getMessage(), is("test1,test2"));
}
 
Example 24
Source Project: dubbo-2.6.5   Source File: SpringStatusCheckerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutLifeCycleRunning() {
    ApplicationLifeCycle applicationLifeCycle = mock(ApplicationLifeCycle.class);
    new ServiceBean<Object>().setApplicationContext(applicationLifeCycle);
    given(applicationLifeCycle.isRunning()).willReturn(false);

    Status status = springStatusChecker.check();

    assertThat(status.getLevel(), is(Status.Level.ERROR));
}
 
Example 25
Source Project: dubbo3   Source File: MemoryStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    Runtime runtime = Runtime.getRuntime();
    long freeMemory = runtime.freeMemory();
    long totalMemory = runtime.totalMemory();
    long maxMemory = runtime.maxMemory();
    boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于2M报警
    String msg = "Max:" + (maxMemory / 1024 / 1024) + "M, Total:" 
    + (totalMemory / 1024 / 1024) + "M, Free:" + (freeMemory / 1024 / 1024) 
    + "M, Use:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M";
    return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg);
}
 
Example 26
Source Project: dubbo3   Source File: DatabaseStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    boolean ok;
    try {
        Connection connection = dataSource.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet resultSet = metaData.getTypeInfo();
            try {
                ok = resultSet.next();
            } finally {
                resultSet.close();
            }
            if (message == null) {
                message = metaData.getURL()
                    + " (" + metaData.getDatabaseProductName() 
                    + " " + metaData.getDatabaseProductVersion()
                    + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
            }
            if (version == 0) {
                version = metaData.getDatabaseMajorVersion();
            }
        } finally {
            connection.close();
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        ok = false;
    }
    return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
 
Example 27
Source Project: dubbo-2.6.5   Source File: DataSourceStatusCheckerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithDatasourceNotHasNextResult() throws SQLException {
    Map<String, DataSource> map = new HashMap<String, DataSource>();
    DataSource dataSource = mock(DataSource.class);
    Connection connection = mock(Connection.class, Answers.RETURNS_DEEP_STUBS);
    given(dataSource.getConnection()).willReturn(connection);
    given(connection.getMetaData().getTypeInfo().next()).willReturn(false);

    map.put("mockDatabase", dataSource);
    given(applicationContext.getBeansOfType(eq(DataSource.class), anyBoolean(), anyBoolean())).willReturn(map);
    Status status = dataSourceStatusChecker.check();

    assertThat(status.getLevel(), is(Status.Level.ERROR));
}
 
Example 28
Source Project: dubbo-2.6.5   Source File: RegistryStatusCheckerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckOK() {
    ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension().getRegistry(registryUrl);
    ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension().getRegistry(registryUrl2);
    assertEquals(Status.Level.OK, new RegistryStatusChecker().check().getLevel());
    String message = new RegistryStatusChecker().check().getMessage();
    Assert.assertTrue(message.contains(registryUrl.getAddress() + "(connected)"));
    Assert.assertTrue(message.contains(registryUrl2.getAddress() + "(connected)"));
}
 
Example 29
Source Project: open-capacity-platform   Source File: LoadStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 30
Source Project: dubbox   Source File: StatusPageHandler.java    License: 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";
}