Class: Collection

Collection

A Simple collection that stores names and a Metric instances with a few convenience methods for
creating / registering and then gathering all data the registered metrics.


new Collection( [name])

Creates a named collection of metrics

Parameters:
Name Type Argument Description
name string <optional>

The name to use for this collection.

Source:
Example
var { Collection } = require('measured');
const collection = new Collection('node-process-metrics');
const gauge = collection.gauge('node.process.heap_used', () => {
   return process.memoryUsage().heapUsed;
});

Methods


cachedGauge(name, valueProducingPromiseCallback, updateIntervalInSeconds)

Gets or creates and registers a SettableGauge

Parameters:
Name Type Description
name string

The metric name

valueProducingPromiseCallback function

A function that returns a promise than when
resolved supplies the value that should be cached in this gauge.

updateIntervalInSeconds number

How often the cached gauge should update it's value.

Source:
Returns:
Type
CachedGauge

counter(name [, properties])

Gets or creates and registers a Counter

Parameters:
Name Type Argument Description
name string

The metric name

properties CounterProperties <optional>

See CounterProperties

Source:
Returns:
Type
Counter

end()

Calls end on all metrics in the registry that support end()

Source:

gauge(name, readFn)

Gets or creates and registers a Gauge

Parameters:
Name Type Description
name string

The metric name

readFn function

See Gauge

Source:
Returns:
Type
Gauge

histogram(name [, properties])

Gets or creates and registers a Histogram

Parameters:
Name Type Argument Description
name string

The metric name

properties HistogramProperties <optional>

See HistogramProperties

Source:
Returns:
Type
Histogram

meter(name [, properties])

Gets or creates and registers a Meter

Parameters:
Name Type Argument Description
name string

The metric name

properties MeterProperties <optional>

See MeterProperties

Source:
Returns:
Type
Meter

register(name, metric)

register a metric that was created outside the provided convenience methods of this collection

Parameters:
Name Type Description
name

The metric name

metric

The Metric implementation

Source:
Example
var { Collection, Gauge } = require('measured');
const collection = new Collection('node-process-metrics');
const gauge = new Gauge(() => {
   return process.memoryUsage().heapUsed;
});
collection.register('node.process.heap_used', gauge);

settableGauge(name [, properties])

Gets or creates and registers a SettableGauge

Parameters:
Name Type Argument Description
name string

The metric name

properties SettableGaugeProperties <optional>

See SettableGaugeProperties

Source:
Returns:
Type
SettableGauge

timer(name [, properties])

Gets or creates and registers a Timer

Parameters:
Name Type Argument Description
name string

The metric name

properties TimerProperties <optional>

See TimerProperties

Source:
Returns:
Type
Timer

toJSON()

Fetches the data/values from all registered metrics

Source:
Returns:

The combined JSON object

Type
Object