}
});
}
try {
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(
ManagementFactory.getPlatformMBeanServer(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
OperatingSystemMXBean.class);
if (operatingSystemMXBean.getSystemLoadAverage() >= 0) {
metrics.put("os.cpu.queueLength", new Gauge<Double>() {
@Override
public Double getValue() {
return Math.max(0.0, operatingSystemMXBean.getSystemLoadAverage() - operatingSystemMXBean.getAvailableProcessors());
}
});
metrics.put("os.cpu.load.1m", new Gauge<Double>() {
@Override
public Double getValue() {
return operatingSystemMXBean.getSystemLoadAverage();
}
});
}
} catch (IOException e) {
logger.warn(e.getMessage() + " (this exception is ignored)", e);