From e85fd4bcd047b8258e3bcf5ed9693f3ba1f4b397 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 17 Sep 2015 23:29:32 -0700 Subject: [PATCH] Add counters for stat recording --- lib/channel/chat.js | 3 +++ lib/counters.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/counters.js diff --git a/lib/channel/chat.js b/lib/channel/chat.js index a395d521..90df4502 100644 --- a/lib/channel/chat.js +++ b/lib/channel/chat.js @@ -5,6 +5,7 @@ var ChannelModule = require("./module"); var util = require("../utilities"); var Flags = require("../flags"); var url = require("url"); +var counters = require("../counters"); const SHADOW_TAG = "[shadow]"; const LINK = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig; @@ -122,6 +123,7 @@ ChatModule.prototype.shadowMutedUsers = function () { ChatModule.prototype.handleChatMsg = function (user, data) { var self = this; + counters.add("chat:incoming"); if (!this.channel || !this.channel.modules.permissions.canChat(user)) { return; @@ -304,6 +306,7 @@ ChatModule.prototype.processChatMsg = function (user, data) { return; } this.sendMessage(msgobj); + counters.add("chat:sent"); }; ChatModule.prototype.formatMessage = function (username, data) { diff --git a/lib/counters.js b/lib/counters.js new file mode 100644 index 00000000..b72bbb55 --- /dev/null +++ b/lib/counters.js @@ -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);