Promise based metrics library to dump metrics in a format consumable by datadog and librato drains
npm install @plan3-relate/log-promise-metrics
const metricsFactory = require('@plan3-relate/log-promise-metrics')(console.log, 'baseName');
const metrics = metricsFactory();
const getAllValues = require('request-promise')({url: ...});
metrics.timed('getAllValues', getAllValues)
// some then's after
.then(() => metrics.dropToLogs());
// measure#baseName.getAllValues.success_duration=10ms
// or
// measure#baseName.getAllValues.error_duration=10ms
const sessionCountPromise = Promise.resolve(['0000', '0001', '0002']);
metrics.increment('sessionsCount', v => v.length, sessionCountPromise)
// some then's after
.then(() => metrics.dropToLogs());
// count#baseName.sessionsCount=3
metrics.increment('visitorsCount')
// some then's after
.then(() => metrics.dropToLogs());
const elementsInBasketPromise = require('pg-promise')({..}).query('SELECT ...');
metrics.sample('elementsInBasket', v => v, elementsInBasketPromise);
// some then's after
.then(() => metrics.dropToLogs());
// sample#baseName.elementsInBasket=10
... or, to get a histogram of those values:
const elementsInBasketPromise = require('pg-promise')({..}).query('SELECT ...');
metrics.sample('elementsInBasket', v => v, elementsInBasketPromise);
// some then's after
.then(() => metrics.dropToLogs());
// measure#elementsInBasket=42