Record metrics with 'measured'

This commit is contained in:
Marcel Klehr 2013-10-27 17:42:55 +01:00
parent b1b801e7c7
commit 940f114a84
5 changed files with 40 additions and 9 deletions

View File

@ -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;

View File

@ -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

View File

@ -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();
},

3
src/node/stats.js Normal file
View File

@ -0,0 +1,3 @@
var measured = require('measured')
module.exports = measured.createCollection();

View File

@ -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": {