Search in sources :

Example 11 with Meter

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

the class InfluxDbReporterTest method reportsMeters.

@Test
public void reportsMeters() throws Exception {
    final Meter meter = mock(Meter.class);
    when(meter.getCount()).thenReturn(1L);
    when(meter.getOneMinuteRate()).thenReturn(2.0);
    when(meter.getFiveMinuteRate()).thenReturn(3.0);
    when(meter.getFifteenMinuteRate()).thenReturn(4.0);
    when(meter.getMeanRate()).thenReturn(5.0);
    reporter.report(this.map(), this.map(), this.map(), this.map("meter", meter), 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("meter");
        assertThat(point.getFields()).isNotEmpty();
        assertThat(point.getFields()).hasSize(5);
        assertThat(point.getFields()).contains(entry("count", 1L));
        assertThat(point.getFields()).contains(entry("one-minute", 2.0));
        assertThat(point.getFields()).contains(entry("five-minute", 3.0));
        assertThat(point.getFields()).contains(entry("fifteen-minute", 4.0));
        assertThat(point.getFields()).contains(entry("mean-rate", 5.0));
        */
}
Also used : Meter(io.dropwizard.metrics.Meter) InfluxDbPoint(io.dropwizard.metrics.influxdb.data.InfluxDbPoint) Test(org.junit.Test)

Example 12 with Meter

use of io.dropwizard.metrics.Meter 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 13 with Meter

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

the class Slf4jReporterTest method reportsMeterValuesAtError.

@Test
public void reportsMeterValuesAtError() throws Exception {
    final Meter meter = mock(Meter.class);
    when(meter.getCount()).thenReturn(1L);
    when(meter.getMeanRate()).thenReturn(2.0);
    when(meter.getOneMinuteRate()).thenReturn(3.0);
    when(meter.getFiveMinuteRate()).thenReturn(4.0);
    when(meter.getFifteenMinuteRate()).thenReturn(5.0);
    when(logger.isErrorEnabled(marker)).thenReturn(true);
    errorReporter.report(this.map(), this.map(), this.map(), map("test.meter", meter), this.map());
    verify(logger).error(marker, "type={}, name={}, count={}, mean_rate={}, m1={}, m5={}, m15={}, rate_unit={}", "METER", "test.meter", 1L, 2.0, 3.0, 4.0, 5.0, "events/second");
}
Also used : Meter(io.dropwizard.metrics.Meter) Test(org.junit.Test)

Aggregations

Meter (io.dropwizard.metrics.Meter)13 Test (org.junit.Test)10 Timer (io.dropwizard.metrics.Timer)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