SortedTableLogReporter extends ScheduledMetrics2Reporter { @Override public void reportMetrics(Map<MetricName, Gauge> gauges, Map<MetricName, Counter> counters, Map<MetricName, Histogram> histograms, Map<MetricName, Meter> meters, Map<MetricName, Timer> timers) { final Timer.Context time = Stagemonitor.getMetric2Registry().timer(reportingTimeMetricName).time(); StringBuilder sb = new StringBuilder(1000); printWithBanner("Metrics", '=', sb); sb.append('\n'); try { logGauges(gauges, sb); logCounters(counters, sb); logHistograms(histograms, sb); logMeters(meters, sb); logTimers(timers, sb); sb.append('\n'); } catch (Exception e) { log.error(e.getMessage(), e); } finally { log.info(sb.toString()); time.stop(); } } private  SortedTableLogReporter(Builder builder); static Builder forRegistry(Metric2Registry registry); @Override void reportMetrics(Map<MetricName, Gauge> gauges,
							  Map<MetricName, Counter> counters,
							  Map<MetricName, Histogram> histograms,
							  Map<MetricName, Meter> meters,
							  Map<MetricName, Timer> timers); void printDouble(double d, StringBuilder sb);  }
@Test public void reportsGaugeValues() throws Exception { reporter.reportMetrics(testGauges(), map(), map(), map(), map()); verify(logger).info("Metrics ========================================================================\n" + "\n" + "-- Gauges ----------------------------------------------------------------------\n" + "name | value\n" + " gauge3 | 3\n" + " gauge2 | 2\n" + "gaugeWithLongName1 | 1\n" + "\n" + "\n"); }
@Test public void reportsCounterValues() throws Exception { reporter.reportMetrics(map(), map(name("test.counter").build(), counter(100L)).add(name("test.counter2").build(), counter(200L)), map(), map(), map()); verify(logger).info("Metrics ========================================================================\n" + "\n" + "-- Counters --------------------------------------------------------------------\n" + "name | count\n" + "test.counter2 | 200\n" + " test.counter | 100\n" + "\n" + "\n"); }
@Test public void reportsHistogramValues() throws Exception { reporter.reportMetrics(map(), map(), testHistograms(), map(), map()); verify(logger).info("Metrics ========================================================================\n" + "\n" + "-- Histograms ------------------------------------------------------------------\n" + "name | count | mean | min | max | stddev | p50 | p75 | p95 | p98 | p99 | p999 |\n" + "test.histogram2 | 1 | 400.00 | 400.00 | 200.00 | 500.00 | 600.00 | 700.00 | 800.00 | 900.00 | 1,000.00 | 1,100.00 | \n" + " test.histogram | 1 | 300.00 | 400.00 | 200.00 | 500.00 | 600.00 | 700.00 | 800.00 | 900.00 | 1,000.00 | 1,100.00 | \n" + "\n" + "\n"); }
@Test public void reportsMeterValues() throws Exception { reporter.reportMetrics(map(), map(), map(), map(name("test.meter1").tag("foo", "bar").build(), meter(1L)).add(name("test.meter2").build(), meter(2)), map()); verify(logger).info("Metrics ========================================================================\n" + "\n" + "-- Meters ----------------------------------------------------------------------\n" + "name | count | mean_rate | m1_rate | m5_rate | m15_rate | rate_unit | duration_unit\n" + " test.meter2 | 2 | 2.00 | 3.00 | 4.00 | 5.00 | second | microseconds\n" + "test.meter1,foo=bar | 1 | 2.00 | 3.00 | 4.00 | 5.00 | second | microseconds\n" + "\n" + "\n"); }
@Test public void reportsTimerValues() throws Exception { reporter.reportMetrics(map(), map(), map(), map(), map(name("timer1").build(), timer(400)).add(name("timer2").build(), timer(200)).add(name("timer3").build(), timer(300))); verify(logger).info("Metrics ========================================================================\n" + "\n" + "-- Timers ----------------------------------------------------------------------\n" + "name | count | mean | min | max | stddev | p50 | p75 | p95 | p98 | p99 | p999 | mean_rate | m1_rate | m5_rate | m15_rate | rate_unit | duration_unit\n" + "timer1 | 1 | 0.40 | 0.40 | 0.20 | 0.50 | 0.60 | 0.70 | 0.80 | 0.90 | 1.00 | 1.10 | 2.00 | 3.00 | 4.00 | 5.00 | second | microseconds\n" + "timer3 | 1 | 0.30 | 0.40 | 0.20 | 0.50 | 0.60 | 0.70 | 0.80 | 0.90 | 1.00 | 1.10 | 2.00 | 3.00 | 4.00 | 5.00 | second | microseconds\n" + "timer2 | 1 | 0.20 | 0.40 | 0.20 | 0.50 | 0.60 | 0.70 | 0.80 | 0.90 | 1.00 | 1.10 | 2.00 | 3.00 | 4.00 | 5.00 | second | microseconds\n" + "\n" + "\n"); }