UaaMetricsEmitter { @Scheduled(fixedRate = 5000, initialDelay = 2000) public void emitVmVitals() { OperatingSystemMXBean mbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); String prefix = "vitals.vm."; statsDClient.gauge(prefix + "cpu.count", mbean.getAvailableProcessors()); statsDClient.gauge(prefix + "cpu.load", (long)(mbean.getSystemLoadAverage()*100)); statsDClient.gauge(prefix + "memory.total", mbean.getTotalPhysicalMemorySize()); statsDClient.gauge(prefix + "memory.committed", mbean.getCommittedVirtualMemorySize()); statsDClient.gauge(prefix + "memory.free", mbean.getFreePhysicalMemorySize()); } 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 vm_vitals() { uaaMetricsEmitter.emitVmVitals(); Mockito.verify(statsDClient).gauge(eq("vitals.vm.cpu.count"), gt(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.cpu.load"), geq(0L)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.total"), geq(134217728L)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.committed"), geq(1L)); Mockito.verify(statsDClient).gauge(eq("vitals.vm.memory.free"), geq(1L)); }