A simple, lightweight and extensible metrics gathering system.
$ npm install @dxos/metrics
Metrics can either be submitted to the root object:
import metrics from '@dxos/metrics';
metrics.inc('work.started');
or to a nested object:
import metrics from '@dxos/metrics';
class Test {
_metrics = metrics(Test);
work() {
this._metrics.inc('work.started');
}
}
Nested Metrics objects are scoped and allow for filtering.
metrics.filter({ source: Test, key: 'work.started' });
All metrics are passed up to successive Metrics objects.
import metrics from '@dxos/metrics';
metrics.inc('counter');
metrics.inc('counter');
metrics.inc('counter');
expect(metrics.get('counter').toEqual(metrics.filter({ key: 'counter' }).length);
import metrics from '@dxos/metrics';
const work = async () => {
const period = metrics.start('work');
await new Promise((resolve) => setTimeout(resolve, Math.random() * 100));
period.end();
};
PRs accepted.
GPL-3.0 © dxos