-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmetrics_prometheus.py
More file actions
42 lines (31 loc) · 1.39 KB
/
metrics_prometheus.py
File metadata and controls
42 lines (31 loc) · 1.39 KB
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
import time
from src import ModuleManager, utils
class Module(ModuleManager.BaseModule):
def _float(self, f):
return "{0:.3f}".format(f)
@utils.hook("api.get.prometheus")
def api(self, event):
now = int(time.time())
lines = [
"# HELP server_users Visible user count",
"# TYPE server_users gauge",
"# HELP server_channels Channel count",
"# TYPE server_channels gauge",
"# HELP server_upload Bytes per second uploaded",
"# TYPE server_upload gauge",
"# HELP server_download Bytes per second downloaded",
"# TYPE server_download gauge"
]
for server in self.bot.servers.values():
lines.append("server_users{server=\"%s\"} %d" %
(str(server), len(server.users)))
lines.append("server_channels{server=\"%s\"} %d" %
(str(server), len(server.channels)))
connection_time = time.time()-server.socket.connect_time
lines.append("server_upload{server=\"%s\"} %s" %
(str(server),
self._float(server.socket.bytes_written/connection_time)))
lines.append("server_download{server=\"%s\"} %s" %
(str(server),
self._float(server.socket.bytes_read/connection_time)))
event["response"].write_text("\n".join(lines)+"\n")