Skip to content

Promise based metrics to use with log drains from Librato or DataDog

Notifications You must be signed in to change notification settings

plan3/log-promise-metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

log-promise-metrics

Build Status

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

About

Promise based metrics to use with log drains from Librato or DataDog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published