forked from dbader/node-datadog-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
var loggers = require('./lib/loggers');
var sharedLogger = null;
//
// opts may include:
//
// - apiKey: DataDog API key
// - appKey: DataDog APP key
// - host: Default host for all reported metrics
// - prefix: Default key prefix for all metrics
// - defaultTags: Common tags for all metrics
// - flushIntervalSeconds:
//
// You can also use it to override (dependency-inject) the aggregator
// and reporter instance, which is useful for testing:
//
// - aggregator: an Aggregator instance
// - reporter: a Reporter instance
//
function init(opts) {
opts = opts || {};
opts.flushIntervalSeconds = opts.flushIntervalSeconds || 15;
sharedLogger = new loggers.BufferedMetricsLogger(opts);
}
// This is meant to be curried via bind() so we don't have
// to write wrappers for each metric individually.
function callOnSharedLogger(funcName) {
if (sharedLogger === null) {
init();
}
var args = Array.prototype.slice.call(arguments, 1);
sharedLogger[funcName].apply(sharedLogger, args);
}
module.exports = {
init: init,
flush: callOnSharedLogger.bind(undefined, 'flush'),
gauge: callOnSharedLogger.bind(undefined, 'gauge'),
increment: callOnSharedLogger.bind(undefined, 'increment'),
histogram: callOnSharedLogger.bind(undefined, 'histogram'),
BufferedMetricsLogger: loggers.BufferedMetricsLogger
};