State = require('./irc/state.js'),
IrcConnection = require('./irc/connection.js').IrcConnection,
ClientCommands = require('./clientcommands.js'),
- WebsocketRpc = require('./websocketrpc.js');
+ WebsocketRpc = require('./websocketrpc.js'),
+ Stats = require('./stats.js');
var Client = function (websocket) {
var that = this;
+ Stats.incr('client.created');
+
events.EventEmitter.call(this);
this.websocket = websocket;
+
this.rpc = new WebsocketRpc(this.websocket);
+ this.rpc.on('all', function(func_name, return_fn) {
+ if (typeof func_name === 'string' && typeof return_fn === 'function') {
+ Stats.incr('client.command');
+ Stats.incr('client.command.' + func_name);
+ }
+ });
// Clients address
this.real_address = this.websocket.meta.real_address;
};
Client.prototype.dispose = function () {
+ Stats.incr('client.disposed');
+
this.disposed = true;
this.rpc.dispose();
this.emit('dispose');
_ = require('lodash'),
config = require('./configuration.js'),
winston = require('winston'),
- SettingsGenerator = require('./settingsgenerator.js');
+ SettingsGenerator = require('./settingsgenerator.js'),
+ Stats = require('./stats.js');
request.url = '/index.html';
}
+ if (request.url === '/index.html') {
+ Stats.incr('http.homepage');
+ }
+
// If the 'magic' translation is requested, figure out the best language to use from
// the Accept-Language HTTP header. If nothing is suitible, fallback to our en-gb default translation
if (request.url.substr(0, 16) === '/assets/locales/') {
EE = require('../ee.js'),
iconv = require('iconv-lite'),
Proxy = require('../proxy.js'),
+ Stats = require('../stats.js'),
Socks;
});
this.setMaxListeners(0);
+ Stats.incr('irc.connection.created');
+
options = options || {};
// Socket state
rawSocketConnect.call(that, this);
}
+ Stats.incr('irc.connection.connected');
that.connected = true;
socketConnectHandler.call(that);
}
if (should_reconnect) {
+ Stats.incr('irc.connection.reconnect');
that.reconnect_attempts++;
that.emit('reconnecting');
} else {
+ Stats.incr('irc.connection.closed');
that.emit('close', had_error);
that.reconnect_attempts = 0;
}
var util = require('util'),
EventBinder = require('./eventbinder.js'),
- _ = require('lodash');
+ _ = require('lodash'),
+ Stats = require('../stats.js');
var IrcServer = function (irc_connection) {
this.irc_connection = irc_connection;
function onConnect(event) {
+ Stats.incr('irc.connection.registered');
this.registered = new Date();
this.irc_connection.clientEvent('connect', {
--- /dev/null
+module.exports = {
+ incr: function incr(stat_name) {
+ global.modules.emit('stat counter', {name: stat_name});
+ }
+};
\ No newline at end of file
winston = require('winston'),
Client = require('./client.js').Client,
HttpHandler = require('./httphandler.js').HttpHandler,
- rehash = require('./rehash.js');
+ rehash = require('./rehash.js'),
+ Stats = require('./stats.js');
hs.on('request', function(req, res){
var transport_url = (global.config.http_base_path || '') + '/transport';
+ Stats.incr('http.request');
+
// engine.io can sometimes "loose" the clients remote address. Keep note of it
req.meta = {
remote_address: req.connection.remoteAddress
});
this.ws.on('connection', function(socket) {
+ Stats.incr('http.websocket');
+
initialiseSocket(socket, function(err, authorised) {
var client;
returnFn = this._noop;
}
+ this.emit.apply(this, ['all', packet.method, returnFn].concat(packet.params));
this.emit.apply(this, [packet.method, returnFn].concat(packet.params));
}
};
--- /dev/null
+/**
+ * Stats counter
+ *
+ * Retreive stats for internal kiwi events. Handy for graphing
+ */
+
+var kiwiModules = require('../server/modules'),
+ fs = require('fs');
+
+
+
+var module = new kiwiModules.Module('stats_file');
+
+module.on('stat counter', function (event, event_data) {
+ var stat_name = event_data.name,
+ stats_file, timestamp,
+ ignored_events = [];
+
+ // Some events may want to be ignored
+ ignored_events.push('http.request');
+
+ if (ignored_events.indexOf(stat_name) > -1) {
+ return;
+ }
+
+ timestamp = Math.floor((new Date()).getTime() / 1000);
+
+ stats_file = fs.createWriteStream('kiwi_stats.log', {'flags': 'a'});
+ stats_file.write(timestamp.toString() + ' ' + stat_name + '\n');
+});
\ No newline at end of file