Search in sources :

Example 36 with Gauge

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);
}
Also used : Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 37 with Gauge

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);
}
Also used : ValueList(org.collectd.api.ValueList) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 38 with Gauge

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));
}
Also used : Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) Matchers.anyString(org.mockito.Matchers.anyString) Gauge(com.codahale.metrics.Gauge)

Example 39 with Gauge

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);
}
Also used : Gauge(com.codahale.metrics.Gauge)

Example 40 with 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);
}
Also used : Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Aggregations

Gauge (com.codahale.metrics.Gauge)64 Test (org.junit.Test)43 Counter (com.codahale.metrics.Counter)10 MetricRegistry (com.codahale.metrics.MetricRegistry)9 Meter (com.codahale.metrics.Meter)8 Metric (com.codahale.metrics.Metric)8 Timer (com.codahale.metrics.Timer)7 SortedMap (java.util.SortedMap)7 Histogram (com.codahale.metrics.Histogram)6 Map (java.util.Map)6 Matchers.anyString (org.mockito.Matchers.anyString)3 Snapshot (com.codahale.metrics.Snapshot)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 Semaphore (java.util.concurrent.Semaphore)2 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)2 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)2 ValueList (org.collectd.api.ValueList)2 Assertion (org.opensaml.saml.saml2.core.Assertion)2