@plan3-relate/log-promise-metrics
v1.2.0
Published
Uses stdout to dump metrics in a format consumed by datadog drain or librato
Downloads
5
Readme
log-promise-metrics
Promise based metrics library to dump metrics in a format consumable by datadog and librato drains
Installation
npm install @plan3-relate/log-promise-metrics
Usage
const metricsFactory = require('@plan3-relate/log-promise-metrics')(console.log, 'baseName');
const metrics = metricsFactory();
Measure time passed during promise execution
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
Increment count by given value
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
Increment count by 1
metrics.increment('visitorsCount')
// some then's after
.then(() => metrics.dropToLogs());
Use custom sample
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