diff options
author | Marcel Klehr <mklehr@gmx.net> | 2013-10-27 17:42:55 +0100 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2013-10-27 17:42:55 +0100 |
commit | 940f114a84d8a216e9a3f87f609494b2390d866e (patch) | |
tree | 50e4930289d2f7447a40a765fe9a95e4e3f7047f /src | |
parent | b1b801e7c7dfa5c8a9cda44cbf121cd6651b6845 (diff) | |
download | etherpad-lite-940f114a84d8a216e9a3f87f609494b2390d866e.zip |
Record metrics with 'measured'
Diffstat (limited to 'src')
-rw-r--r-- | src/node/handler/PadMessageHandler.js | 28 | ||||
-rw-r--r-- | src/node/hooks/express/webaccess.js | 14 | ||||
-rwxr-xr-x | src/node/server.js | 1 | ||||
-rw-r--r-- | src/node/stats.js | 3 | ||||
-rw-r--r-- | src/package.json | 3 |
5 files changed, 40 insertions, 9 deletions
diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 6314351b..d1f1cc05 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -36,6 +36,7 @@ var accessLogger = log4js.getLogger("access"); var _ = require('underscore'); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); var channels = require("channels"); +var stats = require('../stats'); /** * A associative array that saves informations about a session @@ -50,6 +51,11 @@ var channels = require("channels"); var sessioninfos = {}; exports.sessioninfos = sessioninfos; +// Measure total amount of users +stats.gauge('totalUsers', function() { + return Object.keys(socketio.sockets.sockets).length +}) + /** * A changeset queue per pad that is processed by handleUserChanges() */ @@ -74,7 +80,9 @@ exports.setSocketIO = function(socket_io) * @param client the new client */ exports.handleConnect = function(client) -{ +{ + stats.meter('connects').mark(); + //Initalize sessioninfos for this new session sessioninfos[client.id]={}; } @@ -99,12 +107,18 @@ exports.kickSessionsFromPad = function(padID) */ exports.handleDisconnect = function(client) { + stats.meter('disconnects').mark(); + //save the padname of this session var session = sessioninfos[client.id]; //if this connection was already etablished with a handshake, send a disconnect message to the others if(session && session.author) { + client.get('remoteAddress', function(er, ip) { + accessLogger.info('[LEAVE] Pad "'+session.padId+'": Author "'+session.author+'" on client '+client.id+' with IP "'+ip+'" left the pad') + }) + //get the author color out of the db authorManager.getAuthorColorId(session.author, function(err, color) { @@ -129,10 +143,6 @@ exports.handleDisconnect = function(client) }); } - client.get('remoteAddress', function(er, ip) { - accessLogger.info('[LEAVE] Pad "'+session.padId+'": Author "'+session.author+'" on client '+client.id+' with IP "'+ip+'" left the pad') - }) - //Delete the sessioninfos entrys of this session delete sessioninfos[client.id]; } @@ -579,6 +589,9 @@ function handleUserChanges(data, cb) var thisSession = sessioninfos[client.id]; var r, apool, pad; + + // Log edit + stats.meter('edits').mark(); async.series([ //get the pad @@ -632,6 +645,7 @@ function handleUserChanges(data, cb) { // There is an error in this changeset, so just refuse it client.json.send({disconnect:"badChangeset"}); + stats.meter('failedChangesets').mark(); return callback(new Error("Can't apply USER_CHANGES, because "+e.message)); } @@ -662,6 +676,7 @@ function handleUserChanges(data, cb) changeset = Changeset.follow(c, changeset, false, apool); }catch(e){ client.json.send({disconnect:"badChangeset"}); + stats.meter('failedChangesets').mark(); return callback(new Error("Can't apply USER_CHANGES, because "+e.message)); } @@ -684,6 +699,7 @@ function handleUserChanges(data, cb) if (Changeset.oldLen(changeset) != prevText.length) { client.json.send({disconnect:"badChangeset"}); + stats.meter('failedChangesets').mark(); return callback(new Error("Can't apply USER_CHANGES "+changeset+" with oldLen " + Changeset.oldLen(changeset) + " to document of length " + prevText.length)); } @@ -792,7 +808,7 @@ exports.updatePadClients = function(pad, callback) } /** - * Copied from the Etherpad Source Code. Don't know what this methode does excatly... + * Copied from the Etherpad Source Code. Don't know what this method does excatly... */ function _correctMarkersInPad(atext, apool) { var text = atext.text; diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js index efced3f7..433d5094 100644 --- a/src/node/hooks/express/webaccess.js +++ b/src/node/hooks/express/webaccess.js @@ -5,6 +5,7 @@ var settings = require('../../utils/Settings'); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); var ueberStore = require('../../db/SessionStore'); +var stats = require('ep_etherpad-lite/node/stats') //checks for basic http auth exports.basicAuth = function (req, res, next) { @@ -91,10 +92,21 @@ exports.basicAuth = function (req, res, next) { exports.secret = null; exports.expressConfigure = function (hook_name, args, cb) { + // Measure response time + args.app.use(function(req, res, next) { + var stopWatch = stats.timer('httpRequests').start(); + var sendFn = res.send + res.send = function() { + stopWatch.end() + sendFn.apply(res, arguments) + } + next() + }) + // If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158. // Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway. if (!(settings.loglevel === "WARN" || settings.loglevel == "ERROR")) - args.app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.DEBUG, format: ':status, :method :url -- :response-timems'})); + args.app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.DEBUG, format: ':status, :method :url'})); /* Do not let express create the session, so that we can retain a * reference to it for socket.io to use. Also, set the key (cookie diff --git a/src/node/server.js b/src/node/server.js index db75d7e3..c098b456 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -48,7 +48,6 @@ async.waterfall([ plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); hooks.plugins = plugins; - callback(); }, diff --git a/src/node/stats.js b/src/node/stats.js new file mode 100644 index 00000000..24efaf4a --- /dev/null +++ b/src/node/stats.js @@ -0,0 +1,3 @@ +var measured = require('measured') + +module.exports = measured.createCollection();
\ No newline at end of file diff --git a/src/package.json b/src/package.json index 4cded19a..2e4c84f4 100644 --- a/src/package.json +++ b/src/package.json @@ -38,7 +38,8 @@ "unorm" : "1.0.0", "languages4translatewiki" : "0.1.3", "swagger-node-express" : "1.2.3", - "channels" : "0.0.x" + "channels" : "0.0.x", + "measured" : "0.1.3" }, "bin": { "etherpad-lite": "./node/server.js" }, "devDependencies": { |