2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-02-24 12:42:27 +00:00
|
|
|
import modules.counters as count
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
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
|
2018-03-14 20:13:40 +00:00
|
|
|
for i in main.IRCPool.keys():
|
|
|
|
numChannels += len(main.IRCPool[i].channels)
|
|
|
|
for i in main.wholist.keys():
|
|
|
|
numWhoEntries += len(main.wholist[i].keys())
|
2018-07-28 20:44:13 +00:00
|
|
|
stats.append("Servers: %s" % len(main.pool.keys()))
|
|
|
|
stats.append("Online ervers: %s" % len(main.IRCPool.keys()))
|
2018-02-23 22:05:40 +00:00
|
|
|
stats.append("Channels: %s" % numChannels)
|
|
|
|
stats.append("User records: %s" % numWhoEntries)
|
2018-02-24 12:42:27 +00:00
|
|
|
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]))
|
2018-02-23 22:05:40 +00:00
|
|
|
info("\n".join(stats))
|
|
|
|
return
|
|
|
|
|
|
|
|
elif length == 2:
|
|
|
|
stats = []
|
|
|
|
numChannels = 0
|
|
|
|
numWhoEntries = 0
|
|
|
|
|
|
|
|
failures = 0
|
2018-03-14 20:13:40 +00:00
|
|
|
if spl[1] in main.IRCPool.keys():
|
|
|
|
numChannels += len(main.IRCPool[spl[1]].channels)
|
2018-02-23 22:05:40 +00:00
|
|
|
else:
|
|
|
|
failure("Name does not exist: %s" % spl[1])
|
|
|
|
failures += 1
|
2018-03-14 20:13:40 +00:00
|
|
|
if spl[1] in main.wholist.keys():
|
|
|
|
numWhoEntries += len(main.wholist[spl[1]].keys())
|
2018-02-23 22:05:40 +00:00
|
|
|
else:
|
|
|
|
failure("Who entry does not exist: %s" % spl[1])
|
|
|
|
failures += 1
|
|
|
|
if failures == 2:
|
|
|
|
failure("No information found, aborting")
|
|
|
|
return
|
|
|
|
stats.append("Channels: %s" % numChannels)
|
|
|
|
stats.append("User records: %s" % numWhoEntries)
|
2018-02-24 12:42:27 +00:00
|
|
|
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]))
|
2018-02-23 22:05:40 +00:00
|
|
|
info("\n".join(stats))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("stats")
|
|
|
|
else:
|
|
|
|
incUsage(None)
|