use of io.dropwizard.metrics.Timer 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);
}
use of io.dropwizard.metrics.Timer in project light-4j by networknt.
the class Slf4jReporterTest method reportsTimerValuesAtError.
@Test
public void reportsTimerValuesAtError() 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.isErrorEnabled(marker)).thenReturn(true);
errorReporter.report(this.map(), this.map(), this.map(), this.map(), map("test.another.timer", timer));
verify(logger).error(marker, "type={}, name={}, count={}, min={}, max={}, mean={}, stddev={}, median={}, p75={}, p95={}, p98={}, p99={}, p999={}, mean_rate={}, m1={}, m5={}, m15={}, rate_unit={}, duration_unit={}", "TIMER", "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");
}
use of io.dropwizard.metrics.Timer in project light-4j by networknt.
the class ConsoleReporterTest 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);
reporter.report(this.map(), this.map(), this.map(), this.map(), map("test.another.timer", timer));
assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Timers ----------------------------------------------------------------------", "test.another.timer", " count = 1", " mean rate = 2.00 calls/second", " 1-minute rate = 3.00 calls/second", " 5-minute rate = 4.00 calls/second", " 15-minute rate = 5.00 calls/second", " min = 300.00 milliseconds", " max = 100.00 milliseconds", " mean = 200.00 milliseconds", " stddev = 400.00 milliseconds", " median = 500.00 milliseconds", " 75% <= 600.00 milliseconds", " 95% <= 700.00 milliseconds", " 98% <= 800.00 milliseconds", " 99% <= 900.00 milliseconds", " 99.9% <= 1000.00 milliseconds", "", ""));
}
use of io.dropwizard.metrics.Timer 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);
}
}
use of io.dropwizard.metrics.Timer 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);
}
Aggregations