Documentation / Reporting

Reporting

Quick links:

MetricReportManager

MetricReportManager is part of avaje-metric-core. What it does is periodically collect the metrics from the MetricManager and send then to any registered reporters. You typically specify the frequency in which metrics should be reported and the reporter(s) to use.

MetricReportManager can support ReportWriters for reporting the aggregate metrics as well as the 'Per request' timings.

Example: MetricReportManager

  import org.avaje.metric.report.MetricReportConfig;
  import org.avaje.metric.report.MetricReportManager;
  ...

  // Default to using the simple FileReporters that come with avaje-metric-core.
  // Writes metrics in a csv format every 60 seconds. Defaults to write a
  // daily file and keep a maximum of 20 files

  MetricReportConfig config = new MetricReportConfig();
  config.setFreqInSeconds(60);

  MetricReportManager reportManager = new MetricReportManager(config);

  

MetricReporter interface

You can write your own MetricReporter implementation.

  package org.avaje.metric.report;

   /**
    * Defines interface for reporting metrics.
    *
    * Construct and then pass the MetricReporter into one
    * of the constructors for MetricReportManager.
    */
    public interface MetricReporter {

   /**
    * Report the collected metrics. These metrics are all
    * known to have non-empty values.
    */
    public void report(ReportMetrics reportMetrics);

   /**
    * Perform periodic cleanup of any resources
    * (e.g. only keep x days of metrics files).
    *
    * By default this will be called approximately every 8 hours
    * and is intended to be used to cleanup old files created by
    * the likes of FileReporter (only keep x days of metrics files).
    */
    public void cleanup();

  }

ReportMetrics Bean:

ReportMetrics is a bean that holds the collected metrics, collection time and environment information (Application, Server, Environment etc).

 /**
  * This is the environment specific information - Application,
  * Environment, Server etc.
  */
  protected final HeaderInfo headerInfo;

 /**
  * The time the metrics were collected. This is used to determine
  * the duration for each metric which is the time since its last collection.
  */
  protected final long collectionTime;

 /**
  * The metrics that were collected that were not empty. Metrics that
  * didn't have events occur are considered empty and not reported.
  */
  protected final List<Metric> metrics;