Search in sources :

Example 1 with Meter

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

the class InstrumentedExecutorServiceTest method reportsTasksInformation.

@Test
public void reportsTasksInformation() throws Exception {
    this.executor = Executors.newCachedThreadPool();
    final InstrumentedExecutorService instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "xs");
    final Meter submitted = registry.meter("xs.submitted");
    final Counter running = registry.counter("xs.running");
    final Meter completed = registry.meter("xs.completed");
    final Timer duration = registry.timer("xs.duration");
    final Meter rejected = registry.meter("xs.rejected");
    assertThat(submitted.getCount()).isEqualTo(0);
    assertThat(running.getCount()).isEqualTo(0);
    assertThat(completed.getCount()).isEqualTo(0);
    assertThat(duration.getCount()).isEqualTo(0);
    assertThat(rejected.getCount()).isEqualTo(0);
    Future<?> theFuture = instrumentedExecutorService.submit(() -> {
        assertThat(submitted.getCount()).isEqualTo(1);
        assertThat(running.getCount()).isEqualTo(1);
        assertThat(completed.getCount()).isEqualTo(0);
        assertThat(duration.getCount()).isEqualTo(0);
        assertThat(rejected.getCount()).isEqualTo(0);
    });
    theFuture.get();
    assertThat(submitted.getCount()).isEqualTo(1);
    assertThat(running.getCount()).isEqualTo(0);
    assertThat(completed.getCount()).isEqualTo(1);
    assertThat(duration.getCount()).isEqualTo(1);
    assertThat(duration.getSnapshot().size()).isEqualTo(1);
    assertThat(rejected.getCount()).isEqualTo(0);
}
Also used : InstrumentedExecutorService(io.dropwizard.metrics.InstrumentedExecutorService) Counter(io.dropwizard.metrics.Counter) Timer(io.dropwizard.metrics.Timer) Meter(io.dropwizard.metrics.Meter) Test(org.junit.Test)

Example 2 with Meter

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

the class Slf4jReporterTest method reportsMeterValues.

@Test
public void reportsMeterValues() 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.isInfoEnabled(marker)).thenReturn(true);
    infoReporter.report(this.map(), this.map(), this.map(), map("test.meter", meter), this.map());
    verify(logger).info(marker, "type={}, name={}, count={}, mean_rate={}, m1={}, m5={}, m15={}, rate_unit={}", "METER", "prefix.test.meter", 1L, 2.0, 3.0, 4.0, 5.0, "events/second");
}
Also used : Meter(io.dropwizard.metrics.Meter) Test(org.junit.Test)

Example 3 with Meter

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

Example 4 with Meter

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

the class InstrumentedExecutorServiceTest method reportsRejected.

@Test
public void reportsRejected() throws Exception {
    final BlockingQueue<Runnable> queueCapacityOne = new LinkedBlockingQueue<>(1);
    this.executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, queueCapacityOne);
    final InstrumentedExecutorService instrumented = new InstrumentedExecutorService(executor, registry, "r");
    final CountDownLatch finish = new CountDownLatch(1);
    final Meter submitted = registry.meter("r.submitted");
    final Counter running = registry.counter("r.running");
    final Meter completed = registry.meter("r.completed");
    final Timer duration = registry.timer("r.duration");
    final Meter rejected = registry.meter("r.rejected");
    assertThat(submitted.getCount()).isEqualTo(0);
    assertThat(running.getCount()).isEqualTo(0);
    assertThat(completed.getCount()).isEqualTo(0);
    assertThat(duration.getCount()).isEqualTo(0);
    assertThat(rejected.getCount()).isEqualTo(0);
    final List<Future<Object>> futures = new ArrayList<>();
    // Start two callables - one to run on thread and one to be added to queue
    for (int i = 0; i < 2; i++) {
        futures.add(instrumented.submit(() -> {
            finish.await();
            return null;
        }));
    }
    try {
        // Attempt to submit third callable - should fail
        instrumented.submit(() -> {
            throw new IllegalStateException("Shouldn't run this task");
        });
        failBecauseExceptionWasNotThrown(RejectedExecutionException.class);
    } catch (RejectedExecutionException e) {
    // Expected
    } finally {
        finish.countDown();
        for (Future future : futures) {
            future.get();
        }
    }
    assertThat(submitted.getCount()).isEqualTo(3);
    assertThat(running.getCount()).isEqualTo(0);
    assertThat(completed.getCount()).isEqualTo(2);
    assertThat(duration.getCount()).isEqualTo(2);
    assertThat(rejected.getCount()).isEqualTo(1);
}
Also used : InstrumentedExecutorService(io.dropwizard.metrics.InstrumentedExecutorService) Meter(io.dropwizard.metrics.Meter) ArrayList(java.util.ArrayList) Counter(io.dropwizard.metrics.Counter) Timer(io.dropwizard.metrics.Timer) Test(org.junit.Test)

Example 5 with Meter

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

the class ConsoleReporterTest method reportsMeterValues.

@Test
public void reportsMeterValues() 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);
    reporter.report(this.map(), this.map(), this.map(), map("test.meter", meter), this.map());
    assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Meters ----------------------------------------------------------------------", "test.meter", "             count = 1", "         mean rate = 2.00 events/second", "     1-minute rate = 3.00 events/second", "     5-minute rate = 4.00 events/second", "    15-minute rate = 5.00 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