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
- MetricCollection
- new exports.MetricCollection()
- .clear()
- .list() ⇒
Array.<string> - .create(name, [buffer_size]) ⇒
AbstractMetric - .add(name, metric)
- .get(name) ⇒
AbstractMetric|undefined
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
| Param | Type | Description |
|---|---|---|
| name | string | |
| [buffer_size] | number | The 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
| Param | Type |
|---|---|
| name | string |
| metric | AbstractMetric |
metricCollection.get(name) ⇒ AbstractMetric | undefined
Kind: instance method of MetricCollection
| Param | Type |
|---|---|
| name | string |