use of com.codahale.metrics.Snapshot in project metrics by dropwizard.
the class GraphiteReporterTest 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(map(), map(), map("histogram", histogram), map(), map());
final InOrder inOrder = inOrder(graphite);
inOrder.verify(graphite).connect();
inOrder.verify(graphite).send("prefix.histogram.count", "1", timestamp);
inOrder.verify(graphite).send("prefix.histogram.max", "2", timestamp);
inOrder.verify(graphite).send("prefix.histogram.mean", "3.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.min", "4", timestamp);
inOrder.verify(graphite).send("prefix.histogram.stddev", "5.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p50", "6.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p75", "7.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p95", "8.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p98", "9.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p99", "10.00", timestamp);
inOrder.verify(graphite).send("prefix.histogram.p999", "11.00", timestamp);
inOrder.verify(graphite).flush();
inOrder.verify(graphite).close();
verifyNoMoreInteractions(graphite);
}
use of com.codahale.metrics.Snapshot in project metrics by dropwizard.
the class GraphiteReporter method reportTimer.
private void reportTimer(String name, Timer timer, long timestamp) throws IOException {
final Snapshot snapshot = timer.getSnapshot();
sendIfEnabled(MAX, name, convertDuration(snapshot.getMax()), timestamp);
sendIfEnabled(MEAN, name, convertDuration(snapshot.getMean()), timestamp);
sendIfEnabled(MIN, name, convertDuration(snapshot.getMin()), timestamp);
sendIfEnabled(STDDEV, name, convertDuration(snapshot.getStdDev()), timestamp);
sendIfEnabled(P50, name, convertDuration(snapshot.getMedian()), timestamp);
sendIfEnabled(P75, name, convertDuration(snapshot.get75thPercentile()), timestamp);
sendIfEnabled(P95, name, convertDuration(snapshot.get95thPercentile()), timestamp);
sendIfEnabled(P98, name, convertDuration(snapshot.get98thPercentile()), timestamp);
sendIfEnabled(P99, name, convertDuration(snapshot.get99thPercentile()), timestamp);
sendIfEnabled(P999, name, convertDuration(snapshot.get999thPercentile()), timestamp);
reportMetered(name, timer, timestamp);
}
use of com.codahale.metrics.Snapshot in project metrics by dropwizard.
the class MetricsModuleTest method serializesTimers.
@Test
public void serializesTimers() 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(snapshot.getValues()).thenReturn(new long[] { TimeUnit.MILLISECONDS.toNanos(1), TimeUnit.MILLISECONDS.toNanos(2), TimeUnit.MILLISECONDS.toNanos(3) });
when(timer.getSnapshot()).thenReturn(snapshot);
assertThat(mapper.writeValueAsString(timer)).isEqualTo("{" + "\"count\":1," + "\"max\":100.0," + "\"mean\":200.0," + "\"min\":300.0," + "\"p50\":500.0," + "\"p75\":600.0," + "\"p95\":700.0," + "\"p98\":800.0," + "\"p99\":900.0," + "\"p999\":1000.0," + "\"stddev\":400.0," + "\"m15_rate\":5.0," + "\"m1_rate\":3.0," + "\"m5_rate\":4.0," + "\"mean_rate\":2.0," + "\"duration_units\":\"milliseconds\"," + "\"rate_units\":\"calls/second\"}");
final ObjectMapper fullMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, true, MetricFilter.ALL));
assertThat(fullMapper.writeValueAsString(timer)).isEqualTo("{" + "\"count\":1," + "\"max\":100.0," + "\"mean\":200.0," + "\"min\":300.0," + "\"p50\":500.0," + "\"p75\":600.0," + "\"p95\":700.0," + "\"p98\":800.0," + "\"p99\":900.0," + "\"p999\":1000.0," + "\"values\":[1.0,2.0,3.0]," + "\"stddev\":400.0," + "\"m15_rate\":5.0," + "\"m1_rate\":3.0," + "\"m5_rate\":4.0," + "\"mean_rate\":2.0," + "\"duration_units\":\"milliseconds\"," + "\"rate_units\":\"calls/second\"}");
}
use of com.codahale.metrics.Snapshot in project metrics by dropwizard.
the class CollectdReporterTest method reportsHistograms.
@Test
public void reportsHistograms() throws Exception {
Histogram histogram = mock(Histogram.class);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getCount()).thenReturn(1L);
when(histogram.getSnapshot()).thenReturn(snapshot);
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);
reporter.report(map(), map(), map("histogram", histogram), map(), map());
for (int i = 1; i <= 11; i++) {
assertThat(nextValues(receiver)).containsExactly((double) i);
}
}
use of com.codahale.metrics.Snapshot in project metrics by dropwizard.
the class CollectdReporter method serializeHistogram.
private void serializeHistogram(MetaData.Builder metaData, Histogram metric) {
final Snapshot snapshot = metric.getSnapshot();
writeValue(metaData, COUNT, (double) metric.getCount());
writeValue(metaData, MAX, (double) snapshot.getMax());
writeValue(metaData, MEAN, snapshot.getMean());
writeValue(metaData, MIN, (double) snapshot.getMin());
writeValue(metaData, STDDEV, snapshot.getStdDev());
writeValue(metaData, P50, snapshot.getMedian());
writeValue(metaData, P75, snapshot.get75thPercentile());
writeValue(metaData, P95, snapshot.get95thPercentile());
writeValue(metaData, P98, snapshot.get98thPercentile());
writeValue(metaData, P99, snapshot.get99thPercentile());
writeValue(metaData, P999, snapshot.get999thPercentile());
}
Aggregations