Skip to content

Commit

Permalink
reporting aggretate connection stats
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 24, 2011
1 parent 40e766c commit e5385e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion lib/plugins/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,19 @@ repl.define('stats', function(master, sock){

// worker stats
sock.title('Workers');
if (master.reportStats) {
sock.row('connections total', sum(master.children, 'connectionsTotal'));
sock.row('connections active', sum(master.children, 'connectionsActive'));
}

master.children.forEach(function(worker){
var stats = '';

// uptime
stats += utils.formatDateRange(new Date, worker.stats.start);

// connections
if (worker.stats.connectionsTotal) {
if (master.reportStats) {
stats += ' ('
+ worker.stats.connectionsActive
+ '/'
Expand All @@ -163,3 +168,19 @@ repl.define('stats', function(master, sock){
});
sock.write('\n');
}, 'Display server statistics');


/**
* Return sum of each `prop` in `arr`.
*
* @param {Array} arr
* @param {String} prop
* @return {Number}
* @api private
*/

function sum(arr, prop){
return arr.reduce(function(sum, obj){
return sum + obj.stats[prop];
}, 0);
};
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.toArray = function(args, index){
arr[i] = args[i];
}
return arr;
}
};

/**
* Format byte-size.
Expand Down

0 comments on commit e5385e8

Please sign in to comment.