Class: Reporter

Reporter

The abstract reporter that specific implementations can extend to create a Self Reporting Metrics Registry Reporter.

SelfReportingMetricsRegistry


<abstract> new Reporter( [options])

Parameters:
Name Type Argument Description
options ReporterOptions <optional>

The optional params to supply when creating a reporter.

Source:
Examples
const os = require('os');
const process = require('process');
const { SelfReportingMetricsRegistry, Reporter } = require('measured-reporting');

// Create a self reporting registry with a named anonymous reporter instance;
const registry = new SelfReportingMetricsRegistry(
  new class ConsoleReporter extends Reporter {
    constructor() {
      super({
        defaultDimensions: {
          hostname: os.hostname(),
          env: process.env['NODE_ENV'] ? process.env['NODE_ENV'] : 'unset'
        }
       })
    }

    _reportMetrics(metrics) {
       metrics.forEach(metric => {
         console.log(JSON.stringify({
           metricName: metric.name,
           dimensions: this._getDimensions(metric),
           data: metric.metricImpl.toJSON()
          }))
      });
    }
 }()
);
// Create a regular class that extends Reporter
class LoggingReporter extends Reporter {
  _reportMetrics(metrics) {
    metrics.forEach(metric => {
      this._log.info(JSON.stringify({
       metricName: metric.name,
       dimensions: this._getDimensions(metric),
       data: metric.metricImpl.toJSON()
      }))
    });
  }
}

Members


<protected> _defaultDimensions :Dimensions

Map of default dimensions, that should be sent with every metric.

Type:
Source:

<protected> _defaultReportingIntervalInSeconds :number

The default reporting interval, a number in seconds.
If not overridden via the {@see ReporterOptions}, defaults to 10 seconds.

Type:
  • number
Source:

<protected> _log :Logger

Loggers to use, defaults to a new console logger if nothing is supplied in options

Type:
  • Logger
Source:

<protected> _resetMetricsOnInterval :boolean

Flag to indicate if metrics should be reset on each reporting interval.
If not overridden via the {@see ReporterOptions}, defaults to false.

Type:
  • boolean
Source:

<protected> _unrefTimers :boolean

Flag to indicate if reporting timers should be unref'd.
If not overridden via the {@see ReporterOptions}, defaults to false.

Type:
  • boolean
Source:

Methods


<protected> _getDimensions(metric)

Parameters:
Name Type Description
metric MetricWrapper

The Wrapped Metric Object.

Source:
Returns:

The left merged default dimensions with the metric specific dimensions

Type
Dimensions

<abstract, protected> _reportMetrics(metrics)

This method gets called with an array of MetricWrapper on an interval, when metrics should be reported.

This is the main method that needs to get implemented when created an aggregator specific reporter.

Parameters:
Name Type Description
metrics Array.<MetricWrapper>

The array of metrics to report.

Source:

reportMetricOnInterval(metricKey, intervalInSeconds)

Informs the reporter to report a metric on a given interval in seconds.

Parameters:
Name Type Description
metricKey string

The metric key for the metric in the metric registry.

intervalInSeconds number

The interval in seconds to report the metric on.

Source:

setRegistry(registry)

Sets the registry, this must be called before reportMetricOnInterval.

Parameters:
Name Type Description
registry DimensionAwareMetricsRegistry
Source:

shutdown()

Clears the intervals that are running to report metrics at an interval, and resets the state.

Source: