monolith/commands/stats.py

57 lines
2.2 KiB
Python
Raw Normal View History

import main
import modules.counters as count
2018-08-27 19:42:49 +00:00
import modules.userinfo as userinfo
class Stats:
def __init__(self, register):
register("stats", self.stats)
def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
stats = []
numChannels = 0
numWhoEntries = 0
for i in main.IRCPool.keys():
numChannels += len(main.IRCPool[i].channels)
2018-08-27 19:42:49 +00:00
numWhoEntries += userinfo.getNumTotalWhoEntries()
stats.append("Servers: %s" % len(main.pool.keys()))
2018-07-30 20:09:34 +00:00
stats.append("Online servers: %s" % len(main.IRCPool.keys()))
stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries)
counterEvents = count.getEvents()
if counterEvents == None:
stats.append("No counters records")
else:
stats.append("Counters:")
for i in counterEvents.keys():
stats.append(" %s: %s" % (i, counterEvents[i]))
info("\n".join(stats))
return
elif length == 2:
stats = []
numChannels = 0
numWhoEntries = 0
if spl[1] in main.IRCPool.keys():
numChannels += len(main.IRCPool[spl[1]].channels)
else:
failure("Name does not exist: %s" % spl[1])
2018-08-27 19:42:49 +00:00
numWhoEntries += userinfo.getNumWhoEntries(spl[1])
stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries)
counterEvents = count.getEvents(spl[1])
if counterEvents == None:
stats.append("No counters records")
else:
stats.append("Counters:")
for i in counterEvents.keys():
stats.append(" %s: %s" % (i, counterEvents[i]))
info("\n".join(stats))
return
else:
incUsage("stats")
else:
incUsage(None)