lib/loggers.js
function BufferedMetricsLogger(opts) {
    this.aggregator = opts.aggregator || new Aggregator(opts.defaultTags);
    this.reporter = opts.reporter || new DataDogReporter(opts.apiKey, opts.appKey, opts.agent);
    this.host = opts.host;
    this.prefix = opts.prefix || '';
    this.flushIntervalSeconds = opts.flushIntervalSeconds;

    if (this.flushIntervalSeconds) {
        debug('Auto-flushing every %d seconds', this.flushIntervalSeconds);
    } else {
        debug('Auto-flushing is disabled');
    }

    var self = this;
    var autoFlushCallback = function() {
        self.flush();
        if (self.flushIntervalSeconds) {
            var interval = self.flushIntervalSeconds * 1000;
            var tid = setTimeout(autoFlushCallback, interval);
            // Let the event loop exit if this is the only active timer.
            tid.unref();
        }
    };

    autoFlushCallback();
}
function BufferedMetricsLogger(opts) {
    this.aggregator = opts.aggregator || new Aggregator(opts.defaultTags);
    this.reporter = opts.reporter || new DataDogReporter(opts.apiKey, opts.appKey, opts.agent);
    this.host = opts.host;
    this.prefix = opts.prefix || '';
    this.flushIntervalSeconds = opts.flushIntervalSeconds;

    if (this.flushIntervalSeconds) {
        debug('Auto-flushing every %d seconds', this.flushIntervalSeconds);
    } else {
        debug('Auto-flushing is disabled');
    }

    var self = this;
    var autoFlushCallback = function() {
        self.flush();
        if (self.flushIntervalSeconds) {
            var interval = self.flushIntervalSeconds * 1000;
            var tid = setTimeout(autoFlushCallback, interval);
            // Let the event loop exit if this is the only active timer.
            tid.unref();
        }
    };

    autoFlushCallback();
}
function BufferedMetricsLogger ( opts ) { this . aggregator = opts . aggregator || new Aggregator ( opts . defaultTags ) ; this . reporter = opts . reporter || new DataDogReporter ( opts . apiKey , opts . appKey , opts . agent ) ; this . host = opts . host ; this . prefix = opts . prefix || '' ; this . flushIntervalSeconds = opts . flushIntervalSeconds ; if ( this . flushIntervalSeconds ) { debug ( 'Auto-flushing every %d seconds' , this . flushIntervalSeconds ) ; } else { debug ( 'Auto-flushing is disabled' ) ; } var self = this ; var autoFlushCallback = function ( ) { self . flush ( ) ; if ( self . flushIntervalSeconds ) { var interval = self . flushIntervalSeconds * 1000 ; var tid = setTimeout ( autoFlushCallback , interval ) ; // Let the event loop exit if this is the only active timer. tid . unref ( ) ; } } ; autoFlushCallback ( ) ; }
This talks to the DataDog HTTP API to log a bunch of metrics.  Because we don't want to fire off an HTTP request for each data point this buffers all metrics in the given time slice and periodically flushes them to DataDog.  Look here if you want to learn more about the DataDog API: >> http://docs.datadoghq.com/guides/metrics/ <<   `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 - agent: a https agent, passed as dogapi's proxy_agent - 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
This talks to the DataDog HTTP API to log a bunch of metrics . Because we don t want to fire off an HTTP request for each data point this buffers all metrics in the given time slice and periodically flushes them to DataDog . Look here if you want to learn more about the DataDog API : >> http : // docs . datadoghq . com / guides / metrics / << 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 - agent : a https agent passed as dogapi s proxy_agent - 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