ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), System.out, MetricPredicate.ALL ); reporter.run();
/** * Enables the console reporter for the given metrics registry, and causes it to print to STDOUT * with the specified period and unrestricted output. * * @param metricsRegistry the metrics registry * @param period the period between successive outputs * @param unit the time unit of {@code period} */ public static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit) { final ConsoleReporter reporter = new ConsoleReporter(metricsRegistry, System.out, MetricPredicate.ALL); reporter.start(period, unit); }
/** * Get metrics reporter * * @return ConsoleReporter */ public static ConsoleReporter metricsReporter() { return new ConsoleReporter(Metrics.defaultRegistry(), System.err, MetricPredicate.ALL); }
/** * Enables the console reporter for the default metrics registry, and causes it to print to * STDOUT with the specified period. * * @param period the period between successive outputs * @param unit the time unit of {@code period} */ public static void enable(long period, TimeUnit unit) { enable(Metrics.defaultRegistry(), period, unit); }
@Override public void processHistogram(MetricName name, Histogram histogram, PrintStream stream) { super.processHistogram(name, histogram, stream); stream.printf(Locale.getDefault(), " count = %d%n", histogram.count()); } }
@Override public void processTimer(MetricName name, Timer timer, PrintStream stream) { processMeter(name, timer, stream); final String durationUnit = abbrev(timer.durationUnit()); final Snapshot snapshot = timer.getSnapshot(); stream.printf(locale, " min = %2.2f%s\n", timer.min(), durationUnit); stream.printf(locale, " max = %2.2f%s\n", timer.max(), durationUnit); stream.printf(locale, " mean = %2.2f%s\n", timer.mean(), durationUnit); stream.printf(locale, " stddev = %2.2f%s\n", timer.stdDev(), durationUnit); stream.printf(locale, " median = %2.2f%s\n", snapshot.getMedian(), durationUnit); stream.printf(locale, " 75%% <= %2.2f%s\n", snapshot.get75thPercentile(), durationUnit); stream.printf(locale, " 95%% <= %2.2f%s\n", snapshot.get95thPercentile(), durationUnit); stream.printf(locale, " 98%% <= %2.2f%s\n", snapshot.get98thPercentile(), durationUnit); stream.printf(locale, " 99%% <= %2.2f%s\n", snapshot.get99thPercentile(), durationUnit); stream.printf(locale, " 99.9%% <= %2.2f%s\n", snapshot.get999thPercentile(), durationUnit); }
@Override public void processMeter(MetricName name, Metered meter, PrintStream stream) { final String unit = abbrev(meter.rateUnit()); stream.printf(locale, " count = %d\n", meter.count()); stream.printf(locale, " mean rate = %2.2f %s/%s\n", meter.meanRate(), meter.eventType(), unit); stream.printf(locale, " 1-minute rate = %2.2f %s/%s\n", meter.oneMinuteRate(), meter.eventType(), unit); stream.printf(locale, " 5-minute rate = %2.2f %s/%s\n", meter.fiveMinuteRate(), meter.eventType(), unit); stream.printf(locale, " 15-minute rate = %2.2f %s/%s\n", meter.fifteenMinuteRate(), meter.eventType(), unit); }
@Override public boolean enable() { try { PrintStream stream = null; if (outfile != null) { log.info("console reporting will be redirected to {} instead of stdout", outfile); stream = new PrintStream(outfile); } else { stream = System.out; } // static enable() methods omit the option of specifying a // predicate. Calling constructor and starting manually // instead final ConsoleReporter reporter = new ConsoleReporter(Metrics.defaultRegistry(), stream, getMetricPredicate()); reporter.start(getPeriod(), getRealTimeunit()); } catch (Exception e) { log.error("Failure while enabling console reporter", e); return false; } return true; }
/** Process stderr options */ private void processStderr() { if (stderrEnabled()) { ConsoleReporter.enable(stderrPrintSecs, TimeUnit.SECONDS); } } }
@Override public void processHistogram(MetricName name, Histogram histogram, PrintStream stream) { stream.printf(" sum = %,2.2f%n", histogram.sum()); super.processHistogram(name, histogram, stream); stream.printf(" count = %d%n", histogram.count()); } } .run();
/** Dump metrics to stderr */ public void dumpMetricsToStderr() { new ConsoleReporter(System.err).run(); }
@Override public boolean enable() { try { PrintStream stream = createPrintStream(); // static enable() methods omit the option of specifying a // predicate. Calling constructor and starting manually // instead final ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), stream, MetricPredicateTransformer.generatePredicate(getPredicate())); reporter.start(getPeriod(), getRealTimeunit()); } catch (Exception e) { log.error("Failure while enabling console reporter", e); return false; } return true; }
ConsoleReporter.enable(1, TimeUnit.SECONDS); break; case FILE:
/** * Dump all the metrics to the PrintStream provided. * * @param out PrintStream to write metrics to. */ public void printToStream(PrintStream out) { out.println(""); new ConsoleReporter(registry, out, MetricPredicate.ALL).run(); }
ConsoleReporter.enable(1, TimeUnit.SECONDS); break; case FILE:
new ConsoleReporter(System.err).run();