From 27834e1211c745b2269049b7f6a33fadf31f8dc7 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 12 Feb 2014 23:52:38 -0600 Subject: [PATCH] ACP stats --- lib/acp.js | 7 +++++ templates/acp.jade | 7 +++-- www/js/acp.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/lib/acp.js b/lib/acp.js index ad5a4773..d2af8b7c 100644 --- a/lib/acp.js +++ b/lib/acp.js @@ -285,6 +285,12 @@ function handleForceUnload(user, data) { Logger.eventlog.log("[acp] " + eventUsername(user) + " forced unload of " + name); } +function handleListStats(user) { + db.listStats(function (err, rows) { + user.socket.emit("acp-list-stats", rows); + }); +} + function init(user) { var s = user.socket; s.on("acp-announce", handleAnnounce.bind(this, user)); @@ -298,6 +304,7 @@ function init(user) { s.on("acp-delete-channel", handleDeleteChannel.bind(this, user)); s.on("acp-list-activechannels", handleListActiveChannels.bind(this, user)); s.on("acp-force-unload", handleForceUnload.bind(this, user)); + s.on("acp-list-stats", handleListStats.bind(this, user)); db.listGlobalBans(function (err, bans) { if (err) { diff --git a/templates/acp.jade b/templates/acp.jade index bfee6fbd..b97775e7 100644 --- a/templates/acp.jade +++ b/templates/acp.jade @@ -118,11 +118,11 @@ html(lang="en") pre#acp-eventlog-text #acp-stats.acp-panel.col-md-12(style="display: none") h3 User Count - canvas#stat_users(width="100%", height="400") + canvas#stat_users(width="1140", height="400") h3 Channel Count - canvas#stat_channels(width="100%", height="400") + canvas#stat_channels(width="1140", height="400") h3 Memory Usage - canvas#stat_mem(width="100%", height="400") + canvas#stat_mem(width="1140", height="400") include footer mixin footer() @@ -132,4 +132,5 @@ html(lang="en") script(src="/sioconfig") script(src="/assets/js/util.js") script(src="/assets/js/paginator.js") + script(src="/assets/js/chart.js") script(src="/js/acp.js") diff --git a/www/js/acp.js b/www/js/acp.js index 1143a146..54f66082 100644 --- a/www/js/acp.js +++ b/www/js/acp.js @@ -441,6 +441,79 @@ function filterEventLog() { $("#acp-eventlog-filter").change(filterEventLog); $("#acp-eventlog-refresh").click(readEventlog); +/* Stats */ + +$("a:contains('Stats')").click(function () { + socket.emit("acp-list-stats"); +}); + +socket.on("acp-list-stats", function (rows) { + var labels = []; + var ucounts = []; + var ccounts = []; + var mcounts = []; + var lastdate = ""; + rows.forEach(function (r) { + var d = new Date(parseInt(r.time)); + var t = ""; + if (d.toDateString() !== lastdate) { + lastdate = d.toDateString(); + t = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(); + t += " " + d.toTimeString().split(" ")[0]; + } else { + t = d.toTimeString().split(" ")[0]; + } + + labels.push(t); + ucounts.push(r.usercount); + ccounts.push(r.chancount); + mcounts.push(r.mem / 1048576); + }); + + var userdata = { + labels: labels, + datasets: [ + { + fillColor: "rgba(151, 187, 205, 0.5)", + strokeColor: "rgba(151, 187, 205, 1)", + pointColor: "rgba(151, 187, 205, 1)", + pointStrokeColor: "#fff", + data: ucounts + } + ] + }; + + var channeldata = { + labels: labels, + datasets: [ + { + fillColor: "rgba(151, 187, 205, 0.5)", + strokeColor: "rgba(151, 187, 205, 1)", + pointColor: "rgba(151, 187, 205, 1)", + pointStrokeColor: "#fff", + data: ccounts + } + ] + }; + + var memdata = { + labels: labels, + datasets: [ + { + fillColor: "rgba(151, 187, 205, 0.5)", + strokeColor: "rgba(151, 187, 205, 1)", + pointColor: "rgba(151, 187, 205, 1)", + pointStrokeColor: "#fff", + data: mcounts + } + ] + }; + + new Chart($("#stat_users")[0].getContext("2d")).Line(userdata); + new Chart($("#stat_channels")[0].getContext("2d")).Line(channeldata); + new Chart($("#stat_mem")[0].getContext("2d")).Line(memdata); +}); + /* Initialize keyed table sorts */ $("table").each(function () { var table = $(this);