com.codahale.metrics.CsvReporter Java Examples

The following examples show how to use com.codahale.metrics.CsvReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartReportingMetricsToCSVBuilder.java    From kite with Apache License 2.0 6 votes vote down vote up
@Override
protected void doNotify(Record notification) {
  for (Object event : Notifications.getLifecycleEvents(notification)) {
    if (event == Notifications.LifecycleEvent.SHUTDOWN) {
      synchronized (REGISTRIES) {
        Map<File, CsvReporter> reporters = REGISTRIES.get(getContext().getMetricRegistry());
        if (reporters != null) {
          CsvReporter reporter = reporters.remove(outputDir);
          if (reporter != null) {
            reporter.stop();
          }
        }
      }
    }
  }
  super.doNotify(notification);
}
 
Example #2
Source File: CSVReporter.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void report(MetricRegistry metricRegistry) {

    JbootMetricCVRReporterConfig cvrReporterConfig = Jboot.config(JbootMetricCVRReporterConfig.class);

    if (StrUtil.isBlank(cvrReporterConfig.getPath())) {
        throw new NullPointerException("csv reporter path must not be null, please config jboot.metrics.reporter.cvr.path in you properties.");
    }

    final CsvReporter reporter = CsvReporter.forRegistry(metricRegistry)
            .formatFor(Locale.US)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(new File(cvrReporterConfig.getPath()));

    reporter.start(1, TimeUnit.SECONDS);
}
 
Example #3
Source File: ResourceSchedulerWrapper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void initMetricsCSVOutput() {
  int timeIntervalMS = conf.getInt(
          SLSConfiguration.METRICS_RECORD_INTERVAL_MS,
          SLSConfiguration.METRICS_RECORD_INTERVAL_MS_DEFAULT);
  File dir = new File(metricsOutputDir + "/metrics");
  if(! dir.exists()
          && ! dir.mkdirs()) {
    LOG.error("Cannot create directory " + dir.getAbsoluteFile());
  }
  final CsvReporter reporter = CsvReporter.forRegistry(metrics)
          .formatFor(Locale.US)
          .convertRatesTo(TimeUnit.SECONDS)
          .convertDurationsTo(TimeUnit.MILLISECONDS)
          .build(new File(metricsOutputDir + "/metrics"));
  reporter.start(timeIntervalMS, TimeUnit.MILLISECONDS);
}
 
Example #4
Source File: ResourceSchedulerWrapper.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void initMetricsCSVOutput() {
  int timeIntervalMS = conf.getInt(
          SLSConfiguration.METRICS_RECORD_INTERVAL_MS,
          SLSConfiguration.METRICS_RECORD_INTERVAL_MS_DEFAULT);
  File dir = new File(metricsOutputDir + "/metrics");
  if(! dir.exists()
          && ! dir.mkdirs()) {
    LOG.error("Cannot create directory " + dir.getAbsoluteFile());
  }
  final CsvReporter reporter = CsvReporter.forRegistry(metrics)
          .formatFor(Locale.US)
          .convertRatesTo(TimeUnit.SECONDS)
          .convertDurationsTo(TimeUnit.MILLISECONDS)
          .build(new File(metricsOutputDir + "/metrics"));
  reporter.start(timeIntervalMS, TimeUnit.MILLISECONDS);
}
 
Example #5
Source File: CsvReporterStarter.java    From fluo with Apache License 2.0 6 votes vote down vote up
@Override
public List<AutoCloseable> start(Params params) {
  SimpleConfiguration config =
      new FluoConfiguration(params.getConfiguration()).getReporterConfiguration("csv");

  String dir = config.getString("dir", "");
  if (!config.getBoolean("enable", false) || dir.isEmpty()) {
    return Collections.emptyList();
  }

  TimeUnit rateUnit = TimeUnit.valueOf(config.getString("rateUnit", "seconds").toUpperCase());
  TimeUnit durationUnit =
      TimeUnit.valueOf(config.getString("durationUnit", "milliseconds").toUpperCase());

  CsvReporter reporter = CsvReporter.forRegistry(params.getMetricRegistry())
      .convertDurationsTo(durationUnit).convertRatesTo(rateUnit).build(new File(dir));
  reporter.start(config.getInt("frequency", 60), TimeUnit.SECONDS);

  log.info("Reporting metrics as csv to directory {}", dir);

  return Collections.singletonList((AutoCloseable) reporter);
}
 
Example #6
Source File: DatastreamServer.java    From brooklin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initializeMetrics() {
  METRIC_INFOS.addAll(ThreadTerminationMonitor.getMetricInfos());
  METRIC_INFOS.addAll(_coordinator.getMetricInfos());
  METRIC_INFOS.addAll(DatastreamResources.getMetricInfos());

  _jmxReporter = JmxReporterFactory.createJmxReporter(METRIC_REGISTRY);

  if (StringUtils.isNotEmpty(_csvMetricsDir)) {
    LOG.info("Starting CsvReporter in " + _csvMetricsDir);
    File csvDir = new File(_csvMetricsDir);
    if (!csvDir.exists()) {
      LOG.info("csvMetricsDir {} doesn't exist, creating it.", _csvMetricsDir);
      if (!csvDir.mkdirs()) {
        LOG.warn("failed to created csvMetricsDir");
      }
    }

    final CsvReporter reporter = CsvReporter.forRegistry(METRIC_REGISTRY)
        .formatFor(Locale.US)
        .convertRatesTo(SECONDS)
        .convertDurationsTo(MILLISECONDS)
        .build(csvDir);
    reporter.start(1, MINUTES);
  }
}
 
Example #7
Source File: Reporter.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static void reportTo(File directory) {
	directory.mkdirs();
	MetricRegistry registry = MetricsUtils.getDefaultRegistry();
	ScheduledReporter csvReporter = CsvReporter.forRegistry(registry)
		.convertRatesTo(TimeUnit.SECONDS)
		.convertDurationsTo(TimeUnit.MILLISECONDS)
		.build(directory);
	csvReporter.report();
}
 
Example #8
Source File: CsvReportingTest.java    From metrics-sql with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws SQLException, IOException {
    csvFolder = tmpFolderRule.newFolder("csv");
    mBeanServer=ManagementFactory.getPlatformMBeanServer();
    metricRegistry = new MetricRegistry();
    csvReporter = CsvReporter.forRegistry(metricRegistry)
            .build(csvFolder);
    proxyFactory = new JdbcProxyFactory(metricRegistry, new DefaultMetricNamingStrategy("csv"));
    rawDataSource = H2DbUtil.createDataSource();
    try(Connection connection = rawDataSource.getConnection()) {
        H2DbUtil.initTable(connection);
    }
    dataSource = proxyFactory.wrapDataSource(rawDataSource);
}
 
Example #9
Source File: Metrics.java    From joinery with GNU General Public License v3.0 5 votes vote down vote up
public static void displayMetrics() {
    ConsoleReporter.forRegistry(registry)
            .build()
            .report();
    CsvReporter.forRegistry(registry)
            .build(new File("target/"))
            .report();
}
 
Example #10
Source File: StreamingMetrics.java    From kylin with Apache License 2.0 5 votes vote down vote up
public void start() {
    switch (METRICS_OPTION) {
    case "":
        logger.info("Skip streaming metricRegistry because it is empty.");
        break;
    // for test purpose
    case "console":
        logger.info("Use console to collect streaming metricRegistry.");
        ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
        consoleReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "csv":
        File metricsFolder = new File("stream_metrics_csv");
        if (!metricsFolder.exists()) {
            boolean res = metricsFolder.mkdirs();
            if (!res) {
                logger.error("Cannot create dir for stream_metrics_csv");
                break;
            }
        }
        logger.info("Collect streaming metricRegistry in csv format.");
        CsvReporter scvReporter = CsvReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build(metricsFolder);
        scvReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "jmx":
        final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
        jmxReporter.start();
        break;
    default:
        logger.info("Skip metricRegistry because the option {} is not identified.", METRICS_OPTION);
    }
}
 
Example #11
Source File: CodahaleMetricsAssembler.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public CodahaleMetricsAssembler withCsvReporter( File outDirectory, long period, TimeUnit timeunit )
{
    declaration.reportersFactories.add( metricRegistry -> {
        CsvReporter reporter = CsvReporter.forRegistry( metricRegistry ).build( outDirectory );
        reporter.start( period, timeunit );
        return reporter;
    });
    return this;
}
 
Example #12
Source File: CsvReporterProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CsvReporter get() {
    return CsvReporter.forRegistry(metricRegistry)
            .formatFor(configuration.getLocale())
            .convertDurationsTo(configuration.getUnitDurations())
            .convertRatesTo(configuration.getUnitRates())
            .filter(new RegexMetricFilter(configuration.getIncludeMetrics()))
            .build(configuration.getDirectory());
}
 
Example #13
Source File: MetricsCsvReporterModule.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(CsvReporter.class).toProvider(CsvReporterProvider.class);

    addConfigBeans();
    addInitializer(MetricsCsvReporterService.class);
}
 
Example #14
Source File: StreamingMetrics.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public void start() {
    switch (METRICS_OPTION) {
    case "":
        logger.info("Skip streaming metricRegistry because it is empty.");
        break;
    // for test purpose
    case "console":
        logger.info("Use console to collect streaming metricRegistry.");
        ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
        consoleReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "csv":
        File metricsFolder = new File("stream_metrics_csv");
        if (!metricsFolder.exists()) {
            boolean res = metricsFolder.mkdirs();
            if (!res) {
                logger.error("Cannot create dir for stream_metrics_csv");
                break;
            }
        }
        logger.info("Collect streaming metricRegistry in csv format.");
        CsvReporter scvReporter = CsvReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build(metricsFolder);
        scvReporter.start(STREAM_METRICS_INTERVAL, TimeUnit.SECONDS);
        break;
    case "jmx":
        final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
        jmxReporter.start();
        break;
    default:
        logger.info("Skip metricRegistry because the option {} is not identified.", METRICS_OPTION);
    }
}
 
Example #15
Source File: CsvReporterProviderTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void get() throws Exception {
    final CsvReporterProvider provider = new CsvReporterProvider(new MetricsCsvReporterConfiguration(), new MetricRegistry());
    final CsvReporter reporter = provider.get();
    assertNotNull(reporter);
}
 
Example #16
Source File: MetricsCsvReporterService.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Inject
public MetricsCsvReporterService(CsvReporter csvReporter, MetricsCsvReporterConfiguration configuration) {
    this.csvReporter = requireNonNull(csvReporter);
    this.configuration = requireNonNull(configuration);
}
 
Example #17
Source File: StartReportingMetricsToCSVBuilder.java    From kite with Apache License 2.0 4 votes vote down vote up
public StartReportingMetricsToCSV(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);      
  
  MetricFilter filter = PatternMetricFilter.parse(getConfigs(), config);
  TimeUnit defaultDurationUnit = getConfigs().getTimeUnit(config, "defaultDurationUnit", TimeUnit.MILLISECONDS);
  TimeUnit defaultRateUnit = getConfigs().getTimeUnit(config, "defaultRateUnit", TimeUnit.SECONDS); 
  long frequency = getConfigs().getNanoseconds(config, "frequency", 10 * 1000L * 1000 * 1000); // 10 seconds
  if (LOG.isTraceEnabled()) {
    LOG.trace("availableLocales: {}", Joiner.on("\n").join(Locale.getAvailableLocales()));
  }
  Locale locale = getConfigs().getLocale(config, "locale", Locale.getDefault());
  this.outputDir = new File(getConfigs().getString(config, "outputDir"));
  validateArguments();
  
  MetricRegistry registry = context.getMetricRegistry();
  synchronized (REGISTRIES) {
    Map<File, CsvReporter> reporters = REGISTRIES.get(registry);
    if (reporters == null) {
      reporters = Maps.newHashMap();
      REGISTRIES.put(registry, reporters);
    }
    CsvReporter reporter = reporters.get(outputDir);
    if (reporter == null) {
      Builder reporterBuilder = CsvReporter.forRegistry(registry)
          .filter(filter)
          .convertDurationsTo(defaultDurationUnit)
          .convertRatesTo(defaultRateUnit)
          .formatFor(locale);
          
      reporter = reporterBuilder.build(outputDir);
      outputDir.mkdirs();
      if (!outputDir.isDirectory()) {
        throw new MorphlineCompilationException("Directory not found: " + outputDir, config);
      }
      if (!outputDir.canWrite()) {
        throw new MorphlineCompilationException("Directory not writeable: " + outputDir, config);
      }
      reporter.start(frequency, TimeUnit.NANOSECONDS);
      reporters.put(outputDir, reporter);
    }
  }
}