public static void setupJvmMetrics() {
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, SYSTEM, LOAD_AVERAGE), new Gauge<Double>() {
@Override
public Double value() {
return operatingSystemMXBean.getSystemLoadAverage();
}
});
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, HEAP_USED), new Gauge<Long>() {
@Override
public Long value() {
MemoryUsage usage = memoryMXBean.getHeapMemoryUsage();
return usage.getUsed();
}
});
Method processCpuTimeMethod = null;
for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
if (method.getName().equals("getProcessCpuTime")) {
method.setAccessible(true);
processCpuTimeMethod = method;
}
}
final double availableProcessors = operatingSystemMXBean.getAvailableProcessors();
if (processCpuTimeMethod != null) {
final Method pctm = processCpuTimeMethod;
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, CPU_USED), new Gauge<Double>() {
private long start = System.nanoTime();
private long lastCpuTime = getProcessCputTime(pctm, operatingSystemMXBean);
@Override
public Double value() {