-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats.py
53 lines (38 loc) · 1.27 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import znc
import collections
class stats(znc.Module):
module_types = [znc.CModInfo.GlobalModule]
description = "Shows ZNC statistics"
def WebRequiresAdmin(self):
return True
def GetWebMenuTitle(self):
return "Statistics"
def OnWebRequest(self, sock, page, tmpl):
stats = collections.OrderedDict()
stats['Users'] = 0
stats['Online'] = 0
stats['Offline'] = 0
stats['Connections'] = 0
stats['Networks'] = 0
stats['Channels'] = 0
users = znc.CZNC.Get().GetUserMap()
for user in users.items():
stats['Users'] += 1
user_clients = user[1].GetAllClients()
if user_clients:
stats['Online'] += 1
else:
stats['Offline'] += 1
for client in user_clients:
stats['Connections'] += 1
nets = user[1].GetNetworks()
for net in nets:
stats['Networks'] += 1
chans = net.GetChans()
for chan in chans:
stats['Channels'] += 1
for k,v in stats.items():
row = tmpl.AddRow("StatsLoop")
row["Statistic"] = str(k)
row["Value"] = str(v)
return True