UaaMetricsEmitter { @Scheduled(fixedRate = 5000, initialDelay = 1000) public void emitGlobalRequestMetrics() throws Exception { try { UaaMetrics metrics = metricsUtils.getUaaMetrics(server); emitGlobalRequestMetrics(metrics); emitGlobalServerStats(metrics); } catch (Exception x) { throwIfOtherThanNotFound(x); } } 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 requestCount_metrics_emitted() throws Exception { Mockito.when(metricsUtils.getUaaMetrics(any())).thenReturn(uaaMetrics1, uaaMetrics2); uaaMetricsEmitter.emitGlobalRequestMetrics(); Mockito.verify(statsDClient).count("requests.global.completed.count", 3087L); Mockito.verify(statsDClient).gauge("requests.global.completed.time", 29L); Mockito.verify(statsDClient).count("requests.global.unhealthy.count", 1L); Mockito.verify(statsDClient).gauge("requests.global.unhealthy.time", 4318L); Mockito.verify(statsDClient).count("requests.global.status_1xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_2xx.count", 2148L); Mockito.verify(statsDClient).count("requests.global.status_3xx.count", 763L); Mockito.verify(statsDClient).count("requests.global.status_4xx.count", 175L); Mockito.verify(statsDClient).count("requests.global.status_5xx.count", 1L); Mockito.verify(statsDClient).gauge("server.inflight.count", 3L); Mockito.verify(statsDClient).gauge("server.up.time", 12349843L); Mockito.verify(statsDClient).gauge("server.idle.time", 12349L); Mockito.verify(statsDClient).count("database.global.completed.count", 83797L); Mockito.verify(statsDClient).gauge("database.global.completed.time", 0L); Mockito.verify(statsDClient).count("database.global.unhealthy.count", 17549L); Mockito.verify(statsDClient).gauge("database.global.unhealthy.time", 0L); reset(statsDClient); uaaMetricsEmitter.emitGlobalRequestMetrics(); Mockito.verify(statsDClient).count("requests.global.completed.count", 4L); Mockito.verify(statsDClient).count("requests.global.unhealthy.count", 1L); Mockito.verify(statsDClient).count("requests.global.status_1xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_2xx.count", 1L); Mockito.verify(statsDClient).count("requests.global.status_3xx.count", 1L); Mockito.verify(statsDClient).count("requests.global.status_4xx.count", 1L); Mockito.verify(statsDClient).count("requests.global.status_5xx.count", 1L); Mockito.verify(statsDClient).count("database.global.completed.count", 2L); Mockito.verify(statsDClient).count("database.global.unhealthy.count", 5L); reset(statsDClient); uaaMetricsEmitter.emitGlobalRequestMetrics(); Mockito.verify(statsDClient).count("requests.global.completed.count", 0L); Mockito.verify(statsDClient).count("requests.global.unhealthy.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_1xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_2xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_3xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_4xx.count", 0L); Mockito.verify(statsDClient).count("requests.global.status_5xx.count", 0L); Mockito.verify(statsDClient).count("database.global.completed.count", 0L); Mockito.verify(statsDClient).count("database.global.unhealthy.count", 0L); }