Add more counters for diagnostic information

This commit is contained in:
calzoneman 2015-10-28 23:38:17 -07:00
parent 566e932e7e
commit a8cc8e4b04
3 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,7 @@
var Logger = require('./logger'); var Logger = require('./logger');
var counterLog = new Logger.Logger('counters.log'); var counterLog = new Logger.Logger('counters.log');
import os from 'os';
import io from 'socket.io';
var counters = {}; var counters = {};
@ -16,6 +18,13 @@ exports.add = function (counter, value) {
}; };
setInterval(function () { setInterval(function () {
try {
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
counters['load:1min'] = os.loadavg()[0];
counters['socket.io:count'] = io.instance.sockets.length;
counterLog.log(JSON.stringify(counters)); counterLog.log(JSON.stringify(counters));
} catch (e) {
Logger.errlog.log(e.stack);
}
counters = {}; counters = {};
}, 60000); }, 60000);

View file

@ -14,6 +14,7 @@ var util = require("../utilities");
var crypto = require("crypto"); var crypto = require("crypto");
var isTorExit = require("../tor").isTorExit; var isTorExit = require("../tor").isTorExit;
var session = require("../session"); var session = require("../session");
import counters from '../counters';
var CONNECT_RATE = { var CONNECT_RATE = {
burst: 5, burst: 5,
@ -77,6 +78,7 @@ function ipLimitReached(sock) {
var ip = sock._realip; var ip = sock._realip;
sock.on("disconnect", function () { sock.on("disconnect", function () {
counters.add("socket.io:disconnect", 1);
ipCount[ip]--; ipCount[ip]--;
if (ipCount[ip] === 0) { if (ipCount[ip] === 0) {
/* Clear out unnecessary counters to save memory */ /* Clear out unnecessary counters to save memory */
@ -169,6 +171,7 @@ function handleConnection(sock) {
} }
Logger.syslog.log("Accepted socket from " + ip); Logger.syslog.log("Accepted socket from " + ip);
counters.add("socket.io:accept", 1);
addTypecheckedFunctions(sock); addTypecheckedFunctions(sock);

View file

@ -16,6 +16,7 @@ var morgan = require("morgan");
var session = require("../session"); var session = require("../session");
var csrf = require("./csrf"); var csrf = require("./csrf");
var XSS = require("../xss"); var XSS = require("../xss");
import counters from "../counters";
const LOG_FORMAT = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"'; const LOG_FORMAT = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"';
morgan.token('real-address', function (req) { return req._ip; }); morgan.token('real-address', function (req) { return req._ip; });
@ -187,6 +188,7 @@ module.exports = {
*/ */
init: function (app) { init: function (app) {
app.use(function (req, res, next) { app.use(function (req, res, next) {
counters.add("http:request", 1);
req._ip = ipForRequest(req); req._ip = ipForRequest(req);
next(); next();
}); });