Merge pull request #289 from bmhatfield/fix-console

Remove caching from the console backend
This commit is contained in:
Dan Rowe 2013-04-11 08:57:02 -07:00
Родитель 3b1bbac63a e55b095b10
Коммит 18510c0979
1 изменённых файлов: 2 добавлений и 18 удалений

Просмотреть файл

@ -6,33 +6,17 @@ function ConsoleBackend(startupTime, config, emitter){
this.lastException = startupTime;
this.config = config.console || {};
this.statsCache = {
counters: {},
timers: {}
};
// attach
emitter.on('flush', function(timestamp, metrics) { self.flush(timestamp, metrics); });
emitter.on('status', function(callback) { self.status(callback); });
};
ConsoleBackend.prototype.flush = function(timestamp, metrics) {
var self = this;
console.log('Flushing stats at', new Date(timestamp * 1000).toString());
// merge with previously sent values
Object.keys(self.statsCache).forEach(function(type) {
if(!metrics[type]) return;
Object.keys(metrics[type]).forEach(function(name) {
var value = metrics[type][name];
self.statsCache[type][name] || (self.statsCache[type][name] = 0);
self.statsCache[type][name] += value;
});
});
var out = {
counters: this.statsCache.counters,
timers: this.statsCache.timers,
counters: metrics.counters,
timers: metrics.timers,
gauges: metrics.gauges,
timer_data: metrics.timer_data,
counter_rates: metrics.counter_rates,