UaaMetricsEmitter { @Scheduled(fixedRate = 5000, initialDelay = 3000) public void emitJvmVitals() { OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadBean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); String prefix = "vitals.jvm."; statsDClient.gauge(prefix + "cpu.load", (long) (((Number) osBean.getProcessCpuLoad()).doubleValue() * 100)); statsDClient.gauge(prefix + "thread.count", threadBean.getThreadCount()); Map<String, MemoryUsage> memory = new HashMap<>(); memory.put("heap", memoryBean.getHeapMemoryUsage()); memory.put("non-heap", memoryBean.getNonHeapMemoryUsage()); memory.forEach((key, value) -> { statsDClient.gauge(prefix + key + ".init", value.getInit()); statsDClient.gauge(prefix + key + ".committed", value.getCommitted()); statsDClient.gauge(prefix + key + ".used", value.getUsed()); statsDClient.gauge(prefix + key + ".max", value.getMax()); }); } UaaMetricsEmitter(MetricsUtils metricsUtils, StatsDClient statsDClient, MBeanServerConnection server); @Scheduled(fixedRate = 5000, initialDelay = 0) void emitMetrics(); @Scheduled(fixedRate = 5000, initialDelay = 1000) void emitGlobalRequestMetrics(); @Scheduled(fixedRate = 5000, initialDelay = 1000) void emitUrlGroupRequestMetrics(); void emitGlobalServerStats(UaaMetrics metrics); void emitGlobalRequestMetrics(UaaMetrics metrics); @Scheduled(fixedRate = 5000, initialDelay = 2000) void emitVmVitals(); @Scheduled(fixedRate = 5000, initialDelay = 3000) void emitJvmVitals(); void throwIfOtherThanNotFound(Exception x); Number getValueFromBean(Object mbean, String getter); Object getValueFromMap(Map<String, ?> map, String path); void enableNotification(); long getMetricDelta(String name, long gaugeValue); boolean isNotificationEnabled();  }
@Test void jvm_vitals() { uaaMetricsEmitter.emitJvmVitals(); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.cpu.load"), and(geq(0L), leq(100L))); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.thread.count"), and(gt(1L), leq(1000L))); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.init"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.committed"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.heap.used"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.init"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.committed"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.jvm.non-heap.used"), gt(0L)); }