2022-07-21 12:40:09 +00:00
|
|
|
from string import digits
|
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-02-24 12:42:27 +00:00
|
|
|
import modules.counters as count
|
2018-08-27 19:42:49 +00:00
|
|
|
import modules.userinfo as userinfo
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class StatsCommand:
|
2019-01-26 18:58:21 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.stats(*args)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2022-09-05 06:20:30 +00:00
|
|
|
def stats(
|
|
|
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
|
|
|
):
|
2018-02-23 22:05:40 +00:00
|
|
|
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)
|
2018-08-27 19:42:49 +00:00
|
|
|
numWhoEntries += userinfo.getNumTotalWhoEntries()
|
2018-10-21 16:14:50 +00:00
|
|
|
stats.append("Registered servers:")
|
2019-09-28 18:46:10 +00:00
|
|
|
stats.append(" Unique: %s" % len(main.network.keys()))
|
2018-10-21 16:14:50 +00:00
|
|
|
stats.append("Online servers:")
|
|
|
|
stats.append(" Total: %s" % len(main.IRCPool.keys()))
|
|
|
|
stats.append(" Unique: %s" % len(main.liveNets()))
|
2018-02-23 22:05:40 +00:00
|
|
|
stats.append("Channels: %s" % numChannels)
|
|
|
|
stats.append("User records: %s" % numWhoEntries)
|
2019-07-28 14:07:46 +00:00
|
|
|
stats.append("Events/min: %s" % main.lastMinuteSample)
|
2018-02-24 12:42:27 +00:00
|
|
|
counterEvents = count.getEvents()
|
2022-07-21 12:40:05 +00:00
|
|
|
if counterEvents is None:
|
2018-02-24 12:42:27 +00:00
|
|
|
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
|
2018-10-21 16:14:50 +00:00
|
|
|
found = False
|
|
|
|
numNodes = 0
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-10-21 16:14:50 +00:00
|
|
|
for i in main.IRCPool.keys():
|
2022-07-21 12:40:05 +00:00
|
|
|
if "".join([x for x in i if x not in digits]) == spl[1]:
|
2019-03-17 01:22:21 +00:00
|
|
|
numChannels += len(main.IRCPool[i].channels)
|
2018-10-21 16:14:50 +00:00
|
|
|
found = True
|
|
|
|
numNodes += 1
|
|
|
|
if not found:
|
2018-02-23 22:05:40 +00:00
|
|
|
failure("Name does not exist: %s" % spl[1])
|
2018-08-27 19:42:49 +00:00
|
|
|
numWhoEntries += userinfo.getNumWhoEntries(spl[1])
|
2018-02-23 22:05:40 +00:00
|
|
|
stats.append("Channels: %s" % numChannels)
|
|
|
|
stats.append("User records: %s" % numWhoEntries)
|
2018-10-21 16:14:50 +00:00
|
|
|
stats.append("Endpoints: %s" % numNodes)
|
2018-02-24 12:42:27 +00:00
|
|
|
counterEvents = count.getEvents(spl[1])
|
2022-07-21 12:40:05 +00:00
|
|
|
if counterEvents is None:
|
2018-02-24 12:42:27 +00:00
|
|
|
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)
|