/** * Enables the CSV reporter for the given metrics registry, and causes it to write to files in * {@code outputDir} with the specified period. * * @param metricsRegistry the metrics registry * @param outputDir the directory in which {@code .csv} files will be created * @param period the period between successive outputs * @param unit the time unit of {@code period} */ public static void enable(MetricsRegistry metricsRegistry, File outputDir, long period, TimeUnit unit) { final CsvReporter reporter = new CsvReporter(metricsRegistry, outputDir); reporter.start(period, unit); }
@Override public boolean enable() { log.info("Enabling CsvReporter to {}", outdir); try { File foutDir = new File(outdir); boolean success = foutDir.mkdirs(); if (!success) { log.error("Failed to create directory {} for CsvReporter", outdir); return false; } // static enable() methods omit the option of specifying a // predicate. Calling constructor and starting manually // instead final CsvReporter reporter = new CsvReporter(Metrics.defaultRegistry(), getMetricPredicate(), foutDir); reporter.start(getPeriod(), getRealTimeunit()); } catch (Exception e) { log.error("Failure while Enabling CsvReporter", e); return false; } return true; }
@Override public boolean enable() { log.info("Enabling CsvReporter to {}", outdir); try { File foutDir = createFile(); if (foutDir == null) { log.error("Failed to create directory {} for CsvReporter", outdir); return false; } // static enable() methods omit the option of specifying a // predicate. Calling constructor and starting manually // instead final CsvReporter reporter = new CsvReporter( Metrics.defaultRegistry(), MetricPredicateTransformer.generatePredicate(getPredicate()), foutDir); reporter.start(getPeriod(), getRealTimeunit()); } catch (Exception e) { log.error("Failure while Enabling CsvReporter", e); return false; } return true; }
csvReporter.start(updateInterval, TimeUnit.SECONDS);