Search in sources :

Example 1 with Histogram

use of io.dropwizard.metrics.Histogram in project light-4j by networknt.

the class InfluxDbReporterTest method reportsHistograms.

@Test
public void reportsHistograms() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), this.map("histogram", histogram), this.map(), this.map());
    final ArgumentCaptor<InfluxDbPoint> influxDbPointCaptor = ArgumentCaptor.forClass(InfluxDbPoint.class);
    Mockito.verify(influxDb, atLeastOnce()).appendPoints(influxDbPointCaptor.capture());
    InfluxDbPoint point = influxDbPointCaptor.getValue();
/*
        assertThat(point.getMeasurement()).isEqualTo("histogram");
        assertThat(point.getFields()).isNotEmpty();
        assertThat(point.getFields()).hasSize(13);
        assertThat(point.getFields()).contains(entry("max", 2L));
        assertThat(point.getFields()).contains(entry("mean", 3.0));
        assertThat(point.getFields()).contains(entry("min", 4L));
        assertThat(point.getFields()).contains(entry("std-dev", 5.0));
        assertThat(point.getFields()).contains(entry("median", 6.0));
        assertThat(point.getFields()).contains(entry("75-percentile", 7.0));
        assertThat(point.getFields()).contains(entry("95-percentile", 8.0));
        assertThat(point.getFields()).contains(entry("98-percentile", 9.0));
        assertThat(point.getFields()).contains(entry("99-percentile", 10.0));
        assertThat(point.getFields()).contains(entry("999-percentile", 11.0));
        */
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Histogram(io.dropwizard.metrics.Histogram) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint) Test(org.junit.Test)

Example 2 with Histogram

use of io.dropwizard.metrics.Histogram in project light-4j by networknt.

the class MetricRegistryTest method accessingAHistogramRegistersAndReusesIt.

@Test
public void accessingAHistogramRegistersAndReusesIt() throws Exception {
    final Histogram histogram1 = registry.histogram(THING);
    final Histogram histogram2 = registry.histogram(THING);
    assertThat(histogram1).isSameAs(histogram2);
    verify(listener).onHistogramAdded(THING, histogram1);
}
Also used : Histogram(io.dropwizard.metrics.Histogram) Test(org.junit.Test)

Example 3 with Histogram

use of io.dropwizard.metrics.Histogram in project light-4j by networknt.

the class Slf4jReporterTest method reportsHistogramValuesAtError.

@Test
public void reportsHistogramValuesAtError() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    when(logger.isErrorEnabled(marker)).thenReturn(true);
    errorReporter.report(this.map(), this.map(), map("test.histogram", histogram), this.map(), this.map());
    verify(logger).error(marker, "type={}, name={}, count={}, min={}, max={}, mean={}, stddev={}, median={}, p75={}, p95={}, p98={}, p99={}, p999={}", "HISTOGRAM", "test.histogram", 1L, 4L, 2L, 3.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Histogram(io.dropwizard.metrics.Histogram) Test(org.junit.Test)

Example 4 with Histogram

use of io.dropwizard.metrics.Histogram in project light-4j by networknt.

the class ConsoleReporterTest method reportsHistogramValues.

@Test
public void reportsHistogramValues() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), map("test.histogram", histogram), this.map(), this.map());
    assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Histograms ------------------------------------------------------------------", "test.histogram", "             count = 1", "               min = 4", "               max = 2", "              mean = 3.00", "            stddev = 5.00", "            median = 6.00", "              75% <= 7.00", "              95% <= 8.00", "              98% <= 9.00", "              99% <= 10.00", "            99.9% <= 11.00", "", ""));
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Histogram(io.dropwizard.metrics.Histogram) Test(org.junit.Test)

Example 5 with Histogram

use of io.dropwizard.metrics.Histogram in project light-4j by networknt.

the class InfluxDbReporter method report.

@Override
public void report(final SortedMap<MetricName, Gauge> gauges, final SortedMap<MetricName, Counter> counters, final SortedMap<MetricName, Histogram> histograms, final SortedMap<MetricName, Meter> meters, final SortedMap<MetricName, Timer> timers) {
    final long now = System.currentTimeMillis();
    if (logger.isDebugEnabled())
        logger.debug("InfluxDbReporter report is called with counter size " + counters.size());
    try {
        influxDb.flush();
        for (Map.Entry<MetricName, Gauge> entry : gauges.entrySet()) {
            reportGauge(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Counter> entry : counters.entrySet()) {
            reportCounter(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Histogram> entry : histograms.entrySet()) {
            reportHistogram(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Meter> entry : meters.entrySet()) {
            reportMeter(entry.getKey(), entry.getValue(), now);
        }
        for (Map.Entry<MetricName, Timer> entry : timers.entrySet()) {
            reportTimer(entry.getKey(), entry.getValue(), now);
        }
        if (influxDb.hasSeriesData()) {
            influxDb.writeData();
        }
        // reset counters
        for (Map.Entry<MetricName, Counter> entry : counters.entrySet()) {
            Counter counter = entry.getValue();
            long count = counter.getCount();
            counter.dec(count);
        }
    } catch (Exception e) {
        logger.error("Unable to report to InfluxDB. Discarding data.", e);
    }
}
Also used : Histogram(io.dropwizard.metrics.Histogram) Meter(io.dropwizard.metrics.Meter) Gauge(io.dropwizard.metrics.Gauge) MetricName(io.dropwizard.metrics.MetricName) Counter(io.dropwizard.metrics.Counter) Timer(io.dropwizard.metrics.Timer)

Aggregations

Histogram (io.dropwizard.metrics.Histogram)6 Test (org.junit.Test)5 Snapshot (io.dropwizard.metrics.Snapshot)4 Counter (io.dropwizard.metrics.Counter)1 Gauge (io.dropwizard.metrics.Gauge)1 Meter (io.dropwizard.metrics.Meter)1 MetricName (io.dropwizard.metrics.MetricName)1 Timer (io.dropwizard.metrics.Timer)1 InfluxDbPoint (io.dropwizard.metrics.influxdb.data.InfluxDbPoint)1