use of com.codahale.metrics.Gauge in project spring-boot by spring-projects.
the class MetricRepositoryAutoConfigurationTests method dropwizardInstalledIfPresent.
@Test
public void dropwizardInstalledIfPresent() {
this.context = new AnnotationConfigApplicationContext(MetricsDropwizardAutoConfiguration.class, MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertThat(gaugeService).isNotNull();
gaugeService.submit("foo", 2.7);
DropwizardMetricServices exporter = this.context.getBean(DropwizardMetricServices.class);
assertThat(exporter).isEqualTo(gaugeService);
MetricRegistry registry = this.context.getBean(MetricRegistry.class);
@SuppressWarnings("unchecked") Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo");
assertThat(gauge.getValue()).isEqualTo(new Double(2.7));
}
use of com.codahale.metrics.Gauge in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method setupMetricRegistryAndCodahaleMetricsCollector.
private void setupMetricRegistryAndCodahaleMetricsCollector() {
metricRegistryMock = mock(MetricRegistry.class);
cmcMock = mock(CodahaleMetricsCollector.class);
doReturn(metricRegistryMock).when(cmcMock).getMetricRegistry();
registeredTimerMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Timer timerMock = mock(Timer.class);
registeredTimerMocks.put(name, timerMock);
return timerMock;
}).when(metricRegistryMock).timer(anyString());
registeredMeterMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Meter meterMock = mock(Meter.class);
registeredMeterMocks.put(name, meterMock);
return meterMock;
}).when(metricRegistryMock).meter(anyString());
registeredCounterMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Counter counterMock = mock(Counter.class);
registeredCounterMocks.put(name, counterMock);
return counterMock;
}).when(metricRegistryMock).counter(anyString());
registeredHistogramMocks = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Histogram histogramMock = mock(Histogram.class);
registeredHistogramMocks.put(name, histogramMock);
return histogramMock;
}).when(metricRegistryMock).histogram(anyString());
registeredGauges = new HashMap<>();
doAnswer(invocation -> {
String name = invocation.getArgumentAt(0, String.class);
Metric metric = invocation.getArgumentAt(1, Metric.class);
if (metric instanceof Gauge)
registeredGauges.put(name, (Gauge) metric);
else if (metric instanceof Histogram)
registeredHistogramMocks.put(name, (Histogram) metric);
else
throw new RuntimeException("Expected Gauge or Histogram, but received: " + metric.getClass().getName());
return metric;
}).when(metricRegistryMock).register(anyString(), any(Metric.class));
}
use of com.codahale.metrics.Gauge in project alluxio by Alluxio.
the class AlluxioMasterRestServiceHandlerTest method getMetrics.
@Test
public void getMetrics() {
final int FILES_PINNED_TEST_VALUE = 100;
String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
Gauge<Integer> filesPinnedGauge = new Gauge<Integer>() {
@Override
public Integer getValue() {
return FILES_PINNED_TEST_VALUE;
}
};
MetricSet mockMetricsSet = mock(MetricSet.class);
Map<String, Metric> map = new HashMap<>();
map.put(filesPinnedProperty, filesPinnedGauge);
when(mockMetricsSet.getMetrics()).thenReturn(map);
MetricsSystem.METRIC_REGISTRY.registerAll(mockMetricsSet);
Response response = mHandler.getMetrics();
try {
assertNotNull("Response must be not null!", response);
assertNotNull("Response must have a entry!", response.getEntity());
assertTrue("Entry must be a SortedMap!", (response.getEntity() instanceof SortedMap));
SortedMap<String, Long> metricsMap = (SortedMap<String, Long>) response.getEntity();
assertFalse("Metrics Map must be not empty!", (metricsMap.isEmpty()));
assertTrue("Map must contain key " + filesPinnedProperty + "!", metricsMap.containsKey(filesPinnedProperty));
assertEquals(FILES_PINNED_TEST_VALUE, metricsMap.get(filesPinnedProperty).longValue());
} finally {
response.close();
}
}
use of com.codahale.metrics.Gauge in project alluxio by Alluxio.
the class AlluxioWorkerRestServiceHandler method getMetricsInternal.
private Map<String, Long> getMetricsInternal() {
MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
// Get all counters.
Map<String, Counter> counters = metricRegistry.getCounters();
// Only the gauge for cached blocks is retrieved here, other gauges are statistics of
// free/used spaces, those statistics can be gotten via other REST apis.
String blocksCachedProperty = MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.BLOCKS_CACHED);
@SuppressWarnings("unchecked") Gauge<Integer> blocksCached = (Gauge<Integer>) metricRegistry.getGauges().get(blocksCachedProperty);
// Get values of the counters and gauges and put them into a metrics map.
SortedMap<String, Long> metrics = new TreeMap<>();
for (Map.Entry<String, Counter> counter : counters.entrySet()) {
metrics.put(counter.getKey(), counter.getValue().getCount());
}
metrics.put(blocksCachedProperty, blocksCached.getValue().longValue());
return metrics;
}
use of com.codahale.metrics.Gauge in project alluxio by Alluxio.
the class AlluxioMasterRestServiceHandler method getMetricsInternal.
private Map<String, Long> getMetricsInternal() {
MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
// Get all counters.
Map<String, Counter> counters = metricRegistry.getCounters();
// Only the gauge for pinned files is retrieved here, other gauges are statistics of
// free/used
// spaces, those statistics can be gotten via other REST apis.
String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
@SuppressWarnings("unchecked") Gauge<Integer> filesPinned = (Gauge<Integer>) MetricsSystem.METRIC_REGISTRY.getGauges().get(filesPinnedProperty);
// Get values of the counters and gauges and put them into a metrics map.
SortedMap<String, Long> metrics = new TreeMap<>();
for (Map.Entry<String, Counter> counter : counters.entrySet()) {
metrics.put(counter.getKey(), counter.getValue().getCount());
}
metrics.put(filesPinnedProperty, filesPinned.getValue().longValue());
return metrics;
}
Aggregations