Fix socket.io counters

This commit is contained in:
calzoneman 2015-10-30 22:25:00 -07:00
parent 44745d86ac
commit edcf17984f
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@ var Logger = require('./logger');
var counterLog = new Logger.Logger('counters.log');
import os from 'os';
import io from 'socket.io';
import Socket from 'socket.io/lib/socket';
var counters = {};
@ -17,11 +18,17 @@ exports.add = function (counter, value) {
}
};
Socket.prototype._packet = Socket.prototype.packet;
Socket.prototype.packet = function () {
this._packet.apply(this, arguments);
exports.add('socket.io:packet');
};
setInterval(function () {
try {
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
counters['load:1min'] = os.loadavg()[0];
counters['socket.io:count'] = io.instance.sockets.length;
counters['socket.io:count'] = io.instance.sockets.sockets.length;
counterLog.log(JSON.stringify(counters));
} catch (e) {
Logger.errlog.log(e.stack);