use of com.codahale.metrics.Gauge in project metrics by dropwizard.
the class MemoryUsageGaugeSetTest method hasAGaugeForWeirdMemoryPoolUsed.
@Test
public void hasAGaugeForWeirdMemoryPoolUsed() {
final Gauge gauge = (Gauge) gauges.getMetrics().get("pools.Weird-Pool.used");
assertThat(gauge.getValue()).isEqualTo(300L);
}
use of com.codahale.metrics.Gauge in project metrics by dropwizard.
the class CollectdReporterTest method reportsBooleanGauges.
@Test
public void reportsBooleanGauges() throws Exception {
reporter.report(map("gauge", (Gauge) () -> true), map(), map(), map(), map());
ValueList data = receiver.next();
assertThat(data.getValues()).containsExactly(1d);
reporter.report(map("gauge", (Gauge) () -> false), map(), map(), map(), map());
data = receiver.next();
assertThat(data.getValues()).containsExactly(0d);
}
use of com.codahale.metrics.Gauge in project riposte by Nike-Inc.
the class EndpointMetricsHandlerDefaultImplTest method setupMetricRegistryMock.
private void setupMetricRegistryMock() {
metricRegistryMock = mock(MetricRegistry.class);
registeredTimers = new HashMap<>();
doAnswer(invocation -> {
Timer originalTimer = (Timer) invocation.callRealMethod();
return spy(originalTimer);
}).when(instance).createAndRegisterRequestTimer(anyString(), any(MetricRegistry.class));
doThrow(new RuntimeException("All timer creation should go through createAndRegisterRequestTimer(), *not* metricRegistry.timer(...).")).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 Timer)
registeredTimers.put(name, (Timer) metric);
else
throw new RuntimeException("Expected Gauge or Timer, but received: " + metric.getClass().getName());
return metric;
}).when(metricRegistryMock).register(anyString(), any(Metric.class));
}
use of com.codahale.metrics.Gauge in project hive by apache.
the class CodahaleMetrics method addGauge.
@Override
public void addGauge(String name, final MetricsVariable variable) {
Gauge gauge = new Gauge() {
@Override
public Object getValue() {
return variable.getValue();
}
};
addGaugeInternal(name, gauge);
}
use of com.codahale.metrics.Gauge in project metrics by dropwizard.
the class GarbageCollectorMetricSetTest method hasAGaugeForGcTimes.
@Test
public void hasAGaugeForGcTimes() throws Exception {
final Gauge gauge = (Gauge) metrics.getMetrics().get("PS-OldGen.time");
assertThat(gauge.getValue()).isEqualTo(2L);
}
Aggregations