Search in sources :

Example 6 with Timer

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

the class MetricRegistryTest method accessingATimerRegistersAndReusesIt.

@Test
public void accessingATimerRegistersAndReusesIt() throws Exception {
    final Timer timer1 = registry.timer(THING);
    final Timer timer2 = registry.timer(THING);
    assertThat(timer1).isSameAs(timer2);
    verify(listener).onTimerAdded(THING, timer1);
}
Also used : Timer(io.dropwizard.metrics.Timer) Test(org.junit.Test)

Example 7 with Timer

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

the class InfluxDbReporterTest method reportsTimers.

@Test
public void reportsTimers() throws Exception {
    final Timer timer = mock(Timer.class);
    when(timer.getCount()).thenReturn(1L);
    when(timer.getMeanRate()).thenReturn(2.0);
    when(timer.getOneMinuteRate()).thenReturn(3.0);
    when(timer.getFiveMinuteRate()).thenReturn(4.0);
    when(timer.getFifteenMinuteRate()).thenReturn(5.0);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
    when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
    when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
    when(snapshot.getStdDev()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(400));
    when(snapshot.getMedian()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(500));
    when(snapshot.get75thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(600));
    when(snapshot.get95thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(700));
    when(snapshot.get98thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(800));
    when(snapshot.get99thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(900));
    when(snapshot.get999thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(1000));
    when(timer.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), this.map(), this.map(), map("timer", timer));
    final ArgumentCaptor<InfluxDbPoint> influxDbPointCaptor = ArgumentCaptor.forClass(InfluxDbPoint.class);
    Mockito.verify(influxDb, atLeastOnce()).appendPoints(influxDbPointCaptor.capture());
    InfluxDbPoint point = influxDbPointCaptor.getValue();
/*
        assertThat(point.getMeasurement()).isEqualTo("timer");
        assertThat(point.getFields()).isNotEmpty();
        assertThat(point.getFields()).hasSize(17);
        assertThat(point.getFields()).contains(entry("count", 1L));
        assertThat(point.getFields()).contains(entry("mean-rate", 2.0));
        assertThat(point.getFields()).contains(entry("one-minute", 3.0));
        assertThat(point.getFields()).contains(entry("five-minute", 4.0));
        assertThat(point.getFields()).contains(entry("fifteen-minute", 5.0));
        assertThat(point.getFields()).contains(entry("min", 100.0));
        assertThat(point.getFields()).contains(entry("mean", 200.0));
        assertThat(point.getFields()).contains(entry("max", 300.0));
        assertThat(point.getFields()).contains(entry("std-dev", 400.0));
        assertThat(point.getFields()).contains(entry("median", 500.0));
        assertThat(point.getFields()).contains(entry("75-percentile", 600.0));
        assertThat(point.getFields()).contains(entry("95-percentile", 700.0));
        assertThat(point.getFields()).contains(entry("98-percentile", 800.0));
        assertThat(point.getFields()).contains(entry("99-percentile", 900.0));
        assertThat(point.getFields()).contains(entry("999-percentile", 1000.0));
        */
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Timer(io.dropwizard.metrics.Timer) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint) Test(org.junit.Test)

Example 8 with Timer

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

the class SendToLocalInfluxDB method main.

public static void main(String[] args) {
    InfluxDbReporter influxDbReporter = null;
    ScheduledReporter consoleReporter = null;
    Timer.Context context = null;
    try {
        final MetricRegistry registry = new MetricRegistry();
        consoleReporter = startConsoleReporter(registry);
        influxDbReporter = startInfluxDbReporter(registry);
        final Meter myMeter = registry.meter(MetricName.build("testMetric").tagged("env", "test"));
        final Timer myTimer = registry.timer("testTimer");
        context = myTimer.time();
        for (int i = 0; i < 5; i++) {
            myMeter.mark();
            myMeter.mark(Math.round(Math.random() * 100.0));
            Thread.sleep(2000);
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        System.exit(1);
    } finally {
        if (context != null) {
            context.stop();
        }
        if (influxDbReporter != null) {
            influxDbReporter.report();
            influxDbReporter.stop();
        }
        if (consoleReporter != null) {
            consoleReporter.report();
            consoleReporter.stop();
        }
        System.out.println("Finished");
    }
}
Also used : Timer(io.dropwizard.metrics.Timer) Meter(io.dropwizard.metrics.Meter) MetricRegistry(io.dropwizard.metrics.MetricRegistry) InfluxDbReporter(io.dropwizard.metrics.influxdb.InfluxDbReporter) ScheduledReporter(io.dropwizard.metrics.ScheduledReporter)

Example 9 with Timer

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

the class Slf4jReporterTest method reportsTimerValues.

@Test
public void reportsTimerValues() throws Exception {
    final Timer timer = mock(Timer.class);
    when(timer.getCount()).thenReturn(1L);
    when(timer.getMeanRate()).thenReturn(2.0);
    when(timer.getOneMinuteRate()).thenReturn(3.0);
    when(timer.getFiveMinuteRate()).thenReturn(4.0);
    when(timer.getFifteenMinuteRate()).thenReturn(5.0);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
    when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
    when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
    when(snapshot.getStdDev()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(400));
    when(snapshot.getMedian()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(500));
    when(snapshot.get75thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(600));
    when(snapshot.get95thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(700));
    when(snapshot.get98thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(800));
    when(snapshot.get99thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(900));
    when(snapshot.get999thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(1000));
    when(timer.getSnapshot()).thenReturn(snapshot);
    when(logger.isInfoEnabled(marker)).thenReturn(true);
    infoReporter.report(this.map(), this.map(), this.map(), this.map(), map("test.another.timer", timer));
    verify(logger).info(marker, "type={}, name={}, count={}, min={}, max={}, mean={}, stddev={}, median={}, p75={}, p95={}, p98={}, p99={}, p999={}, mean_rate={}, m1={}, m5={}, m15={}, rate_unit={}, duration_unit={}", "TIMER", "prefix.test.another.timer", 1L, 300.0, 100.0, 200.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0, 2.0, 3.0, 4.0, 5.0, "events/second", "milliseconds");
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Timer(io.dropwizard.metrics.Timer) Test(org.junit.Test)

Aggregations

Timer (io.dropwizard.metrics.Timer)9 Test (org.junit.Test)7 Meter (io.dropwizard.metrics.Meter)4 Snapshot (io.dropwizard.metrics.Snapshot)4 Counter (io.dropwizard.metrics.Counter)3 InstrumentedExecutorService (io.dropwizard.metrics.InstrumentedExecutorService)2 Gauge (io.dropwizard.metrics.Gauge)1 Histogram (io.dropwizard.metrics.Histogram)1 MetricName (io.dropwizard.metrics.MetricName)1 MetricRegistry (io.dropwizard.metrics.MetricRegistry)1 ScheduledReporter (io.dropwizard.metrics.ScheduledReporter)1 InfluxDbReporter (io.dropwizard.metrics.influxdb.InfluxDbReporter)1 InfluxDbPoint (io.dropwizard.metrics.influxdb.data.InfluxDbPoint)1 ArrayList (java.util.ArrayList)1