Fix socket.io counters
This commit is contained in:
parent
44745d86ac
commit
edcf17984f
|
@ -2,6 +2,7 @@ var Logger = require('./logger');
|
||||||
var counterLog = new Logger.Logger('counters.log');
|
var counterLog = new Logger.Logger('counters.log');
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import io from 'socket.io';
|
import io from 'socket.io';
|
||||||
|
import Socket from 'socket.io/lib/socket';
|
||||||
|
|
||||||
var counters = {};
|
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 () {
|
setInterval(function () {
|
||||||
try {
|
try {
|
||||||
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
|
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
|
||||||
counters['load:1min'] = os.loadavg()[0];
|
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));
|
counterLog.log(JSON.stringify(counters));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.errlog.log(e.stack);
|
Logger.errlog.log(e.stack);
|
||||||
|
|
Loading…
Reference in a new issue