LoadStatusChecker implements StatusChecker { @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); }  @Override Status check();  }
@Test public void test() throws Exception { LoadStatusChecker statusChecker = new LoadStatusChecker(); Status status = statusChecker.check(); assertThat(status, notNullValue()); logger.info("load status level: " + status.getLevel()); logger.info("load status message: " + status.getMessage()); }