Skip to main content

MetricCollection

MetricCollection

A class for managing a collection of metrics where each metric can store data and be accessed by name. Provides functionality to add, retrieve, list, and clear metrics.

Kind: global class

new exports.MetricCollection()

Example

const metrics = new MetricCollection();
metrics.create({name: "execution time"});

// ... record metrics
const t0 = performance.now();
do_expensive_computation();
const t1 = performance.now();

metrics.get("execution time").record(t1 - t0);

// ... read stats
const stats = metrics.get("execution time").stats;

console.log(`Average execution time: ${stats.mean}`);

metricCollection.clear()

Clear all data records. Note: does not remove any metrics, just the data within them

Kind: instance method of MetricCollection

metricCollection.list() ⇒ Array.<string>

Get names of available metrics

Kind: instance method of MetricCollection

metricCollection.create(name, [buffer_size]) ⇒ AbstractMetric

Kind: instance method of MetricCollection

ParamTypeDescription
namestring
[buffer_size]numberThe larger this number is - the more detail metric can hold. If you plan to compute statistics, this is your sample size.

metricCollection.add(name, metric)

Kind: instance method of MetricCollection

ParamType
namestring
metricAbstractMetric

metricCollection.get(name) ⇒ AbstractMetric | undefined

Kind: instance method of MetricCollection

ParamType
namestring