From a8cc8e4b04b3718f436185094f8b50fa997a6bd0 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 28 Oct 2015 23:38:17 -0700 Subject: [PATCH] Add more counters for diagnostic information --- src/counters.js | 11 ++++++++++- src/io/ioserver.js | 3 +++ src/web/webserver.js | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/counters.js b/src/counters.js index b72bbb55..c3f13f66 100644 --- a/src/counters.js +++ b/src/counters.js @@ -1,5 +1,7 @@ var Logger = require('./logger'); var counterLog = new Logger.Logger('counters.log'); +import os from 'os'; +import io from 'socket.io'; var counters = {}; @@ -16,6 +18,13 @@ exports.add = function (counter, value) { }; setInterval(function () { - counterLog.log(JSON.stringify(counters)); + 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)); + } catch (e) { + Logger.errlog.log(e.stack); + } counters = {}; }, 60000); diff --git a/src/io/ioserver.js b/src/io/ioserver.js index 9ccf6bdd..30af3b18 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -14,6 +14,7 @@ var util = require("../utilities"); var crypto = require("crypto"); var isTorExit = require("../tor").isTorExit; var session = require("../session"); +import counters from '../counters'; var CONNECT_RATE = { burst: 5, @@ -77,6 +78,7 @@ function ipLimitReached(sock) { var ip = sock._realip; sock.on("disconnect", function () { + counters.add("socket.io:disconnect", 1); ipCount[ip]--; if (ipCount[ip] === 0) { /* Clear out unnecessary counters to save memory */ @@ -169,6 +171,7 @@ function handleConnection(sock) { } Logger.syslog.log("Accepted socket from " + ip); + counters.add("socket.io:accept", 1); addTypecheckedFunctions(sock); diff --git a/src/web/webserver.js b/src/web/webserver.js index a15d0d47..c83c3e74 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -16,6 +16,7 @@ var morgan = require("morgan"); var session = require("../session"); var csrf = require("./csrf"); 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"'; morgan.token('real-address', function (req) { return req._ip; }); @@ -187,6 +188,7 @@ module.exports = { */ init: function (app) { app.use(function (req, res, next) { + counters.add("http:request", 1); req._ip = ipForRequest(req); next(); });