private void collectTimerReports( List<DBObject> docs, SortedMap<String, Timer> timers, Date timestamp) { if (timers.isEmpty()) return; for (Map.Entry<String, Timer> entry : timers.entrySet()) { final BasicDBObject report = getBasicDBObject(timestamp, entry.getKey(), "timer"); final Timer v = entry.getValue(); final Snapshot s = v.getSnapshot(); // meter part report.put("count", v.getCount()); report.put("rate-unit", getRateUnit()); report.put("1-minute-rate", convertRate(v.getOneMinuteRate())); report.put("5-minute-rate", convertRate(v.getFiveMinuteRate())); report.put("15-minute-rate", convertRate(v.getFifteenMinuteRate())); report.put("mean-rate", convertRate(v.getMeanRate())); // histogram part report.put("duration-unit", getDurationUnit()); report.put("75-percentile", convertDuration(s.get75thPercentile())); report.put("95-percentile", convertDuration(s.get95thPercentile())); report.put("98-percentile", convertDuration(s.get98thPercentile())); report.put("99-percentile", convertDuration(s.get99thPercentile())); report.put("999-percentile", convertDuration(s.get999thPercentile())); report.put("max", convertDuration(s.getMax())); report.put("min", convertDuration(s.getMin())); report.put("mean", convertDuration(s.getMean())); report.put("median", convertDuration(s.getMedian())); report.put("stddev", convertDuration(s.getStdDev())); docs.add(report); } }
@Test public void reportsTimerValues() throws Exception { final Timer timer = mock(Timer.class); when(timer.getCount()).thenReturn(1L); when(timer.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100)); when(timer.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200)); when(timer.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300)); when(timer.getStdDev()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(400)); 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.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.<Gauge>map(), this.<Counter>map(), this.<Histogram>map(), this.<Meter>map(), map("test.another.timer", timer)); verify(ganglia) .announce( "test.another.timer.max", "100.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.mean", "200.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.min", "300.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.stddev", "400.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p50", "500.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p75", "600.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p95", "700.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p98", "800.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p99", "900.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.p999", "1000.0", GMetricType.DOUBLE, "milliseconds", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.count", "1", GMetricType.DOUBLE, "calls", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.mean_rate", "2.0", GMetricType.DOUBLE, "calls/second", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.m1_rate", "3.0", GMetricType.DOUBLE, "calls/second", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.m5_rate", "4.0", GMetricType.DOUBLE, "calls/second", GMetricSlope.BOTH, 60, 0, "test.another"); verify(ganglia) .announce( "test.another.timer.m15_rate", "5.0", GMetricType.DOUBLE, "calls/second", GMetricSlope.BOTH, 60, 0, "test.another"); verifyNoMoreInteractions(ganglia); }