Add counters for stat recording
This commit is contained in:
parent
f1c61bddb2
commit
e85fd4bcd0
|
|
@ -5,6 +5,7 @@ var ChannelModule = require("./module");
|
||||||
var util = require("../utilities");
|
var util = require("../utilities");
|
||||||
var Flags = require("../flags");
|
var Flags = require("../flags");
|
||||||
var url = require("url");
|
var url = require("url");
|
||||||
|
var counters = require("../counters");
|
||||||
|
|
||||||
const SHADOW_TAG = "[shadow]";
|
const SHADOW_TAG = "[shadow]";
|
||||||
const LINK = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
|
const LINK = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
|
||||||
|
|
@ -122,6 +123,7 @@ ChatModule.prototype.shadowMutedUsers = function () {
|
||||||
|
|
||||||
ChatModule.prototype.handleChatMsg = function (user, data) {
|
ChatModule.prototype.handleChatMsg = function (user, data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
counters.add("chat:incoming");
|
||||||
|
|
||||||
if (!this.channel || !this.channel.modules.permissions.canChat(user)) {
|
if (!this.channel || !this.channel.modules.permissions.canChat(user)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -304,6 +306,7 @@ ChatModule.prototype.processChatMsg = function (user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sendMessage(msgobj);
|
this.sendMessage(msgobj);
|
||||||
|
counters.add("chat:sent");
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.formatMessage = function (username, data) {
|
ChatModule.prototype.formatMessage = function (username, data) {
|
||||||
|
|
|
||||||
21
lib/counters.js
Normal file
21
lib/counters.js
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
var Logger = require('./logger');
|
||||||
|
var counterLog = new Logger.Logger('counters.log');
|
||||||
|
|
||||||
|
var counters = {};
|
||||||
|
|
||||||
|
exports.add = function (counter, value) {
|
||||||
|
if (!value) {
|
||||||
|
value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!counters.hasOwnProperty(counter)) {
|
||||||
|
counters[counter] = value;
|
||||||
|
} else {
|
||||||
|
counters[counter] += value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setInterval(function () {
|
||||||
|
counterLog.log(JSON.stringify(counters));
|
||||||
|
counters = {};
|
||||||
|
}, 60000);
|
||||||
Loading…
Reference in a new issue