Cleaner metrics debug output.
This commit is contained in:
Родитель
0653bb5e24
Коммит
2f6e79aefd
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var sprintf = require('sprintf-js').sprintf;
|
||||
|
||||
function DebugBackend(startupTime, config, emitter) {
|
||||
var backend = this;
|
||||
|
@ -13,24 +14,38 @@ function DebugBackend(startupTime, config, emitter) {
|
|||
}
|
||||
|
||||
DebugBackend.prototype.flush = function(timestamp, metrics) {
|
||||
var out = {
|
||||
counters: metrics.counters,
|
||||
// Do not log individual timers for readability.
|
||||
// timers: metrics.timers,
|
||||
gauges: metrics.gauges,
|
||||
timer_data: metrics.timer_data,
|
||||
counter_rates: metrics.counter_rates,
|
||||
sets: (function(vals) {
|
||||
var ret = {};
|
||||
for (var val in vals) {
|
||||
ret[val] = vals[val].values();
|
||||
}
|
||||
return ret;
|
||||
})(metrics.sets),
|
||||
pctThreshold: metrics.pctThreshold
|
||||
};
|
||||
var report = '';
|
||||
|
||||
console.log(util.inspect(out, false, null, true, true));
|
||||
var elements = '';
|
||||
for (var count in metrics.counters) {
|
||||
if (metrics.counters.hasOwnProperty(count) && metrics.counters[count]) {
|
||||
elements += sprintf('\n%40s %15d', count, metrics.counters[count]);
|
||||
}
|
||||
}
|
||||
if (elements.length) {
|
||||
report += sprintf('\n\n%40s %15s', 'counters', 'num') + elements;
|
||||
}
|
||||
|
||||
elements = '';
|
||||
for (var timer in metrics.timer_data) {
|
||||
if (metrics.timer_data.hasOwnProperty(timer)) {
|
||||
elements += sprintf('\n%40s %10d %10.0f %10.0f %10.0f %10.0f',
|
||||
timer,
|
||||
metrics.timer_data[timer].count,
|
||||
metrics.timer_data[timer].sum,
|
||||
metrics.timer_data[timer].lower,
|
||||
metrics.timer_data[timer].median,
|
||||
metrics.timer_data[timer].upper);
|
||||
}
|
||||
}
|
||||
if (elements.length) {
|
||||
report += sprintf('\n\n%40s %10s %10s %10s %10s %10s',
|
||||
'timers', 'num', 'sum', 'lower', 'median', 'upper') + elements;
|
||||
}
|
||||
|
||||
if (report.length) {
|
||||
console.log('metrics report' + report);
|
||||
}
|
||||
};
|
||||
|
||||
exports.init = function(startupTime, config, events) {
|
||||
|
|
|
@ -37,12 +37,12 @@ var Metrics = function(options) {
|
|||
this.times = {};
|
||||
};
|
||||
|
||||
// Add a client to handle metrics with following interface (all optional):
|
||||
// Add a client object to handle metrics with following (optional) functions:
|
||||
// {
|
||||
// counter: function(key, delta),
|
||||
// gauge: function(key, value),
|
||||
// set: function(key, value),
|
||||
// timing: function(key, start)
|
||||
// timing: function(key, startTime)
|
||||
// }
|
||||
Metrics.prototype.attachClient = function(client) {
|
||||
if (client) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "Secure SPDY Proxy.",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
"postinstall": "cp -f lib/backends/* node_modules/statsd/backends/",
|
||||
"postinstall": "ln -fs lib/backends/* node_modules/statsd/backends/",
|
||||
"pretest": "jscs lib test && jshint lib test",
|
||||
"test": "NODE_ENV=test NODE_CONFIG_DIR=./config/test mocha -R spec -u exports ${MOCHA_ARGS} test/tests/",
|
||||
"start": "node lib/index.js"
|
||||
|
@ -36,9 +36,10 @@
|
|||
"pngquant-bin": "^0.3.1",
|
||||
"redis": "^0.10.3",
|
||||
"spdy": "~1.27.0",
|
||||
"sprintf-js": "0.0.7",
|
||||
"statsd-client": "0.0.15",
|
||||
"temp": "^0.7.0",
|
||||
"winston": "^0.7.3",
|
||||
"statsd-client": "0.0.15",
|
||||
"lzma-native": "^0.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
Загрузка…
Ссылка в новой задаче