|
@@ -0,0 +1,145 @@
|
|
1
|
+#!/usr/bin/env python3
|
|
2
|
+import json
|
|
3
|
+import os
|
|
4
|
+import re
|
|
5
|
+import shlex
|
|
6
|
+import sys
|
|
7
|
+
|
|
8
|
+CONFIG="""\
|
|
9
|
+multigraph rspamd_actions
|
|
10
|
+graph_title Rspamd actions
|
|
11
|
+graph_vlabel mails
|
|
12
|
+graph_args --base 1000 -l 0
|
|
13
|
+graph_category antispam
|
|
14
|
+graph_scale yes
|
|
15
|
+reject.label Rejection
|
|
16
|
+soft_reject.label Soft rejection
|
|
17
|
+rewrite_subject.label Rewrite subject
|
|
18
|
+add_header.label Set headers
|
|
19
|
+greylist.label Graylist
|
|
20
|
+no_action.label No action
|
|
21
|
+scanned.label Scanned/total
|
|
22
|
+learned.label Learned
|
|
23
|
+
|
|
24
|
+multigraph rspamd_result
|
|
25
|
+graph_title Rspamd results
|
|
26
|
+graph_vlabel mails
|
|
27
|
+graph_args --base 1000 -l 0
|
|
28
|
+graph_category antispam
|
|
29
|
+graph_scale yes
|
|
30
|
+spam.label Spams
|
|
31
|
+ham.label Ham
|
|
32
|
+
|
|
33
|
+multigraph rspamd_scantime
|
|
34
|
+graph_title Rspamd scantime
|
|
35
|
+graph_args --base 1000 -l 0
|
|
36
|
+graph_category antispam
|
|
37
|
+graph_scale yes
|
|
38
|
+graph_vlabel seconds
|
|
39
|
+scantime.label Average scantime
|
|
40
|
+
|
|
41
|
+multigraph rspamd_uptime
|
|
42
|
+graph_title Rspamd uptime
|
|
43
|
+graph_args --base 1000 -l 0
|
|
44
|
+graph_category antispam
|
|
45
|
+graph_scale no
|
|
46
|
+graph_vlabel uptime in days
|
|
47
|
+uptime.label uptime
|
|
48
|
+uptime.label uptime
|
|
49
|
+
|
|
50
|
+multigraph rspamd_memory
|
|
51
|
+graph_title Rspamd memory usage
|
|
52
|
+graph_args --base 1024 -l 0
|
|
53
|
+graph_category antispam
|
|
54
|
+graph_scale yes
|
|
55
|
+graph_vlabel bytes
|
|
56
|
+memory.label Memory usage
|
|
57
|
+
|
|
58
|
+multigraph rspamd_connections
|
|
59
|
+graph_title Rspamd connections
|
|
60
|
+graph_args --base 1000 -l 0
|
|
61
|
+graph_category antispam
|
|
62
|
+graph_scale yes
|
|
63
|
+graph_vlabel connections
|
|
64
|
+connections.label opened connections
|
|
65
|
+
|
|
66
|
+multigraph rspamd_ctrl_connections
|
|
67
|
+graph_title Rspamd control connections count
|
|
68
|
+graph_args --base 1000 -l 0
|
|
69
|
+graph_category antispam
|
|
70
|
+graph_scale yes
|
|
71
|
+graph_vlabel connections
|
|
72
|
+connections.label control connections count
|
|
73
|
+"""
|
|
74
|
+
|
|
75
|
+def storage2name(name):
|
|
76
|
+ return re.sub('[\.\- ]', '_', name)
|
|
77
|
+
|
|
78
|
+rspamc='/usr/bin/rspamc'
|
|
79
|
+# TODO check env for rspamc path
|
|
80
|
+cmd = shlex.join([rspamc, '--json', 'stat'])
|
|
81
|
+
|
|
82
|
+with os.popen(cmd, mode='r') as pipe:
|
|
83
|
+ data = json.loads(pipe.read())
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+if len(sys.argv) > 1 and sys.argv[1] == 'config':
|
|
87
|
+ print(CONFIG)
|
|
88
|
+ print('''multigraph rspamd_statfiles
|
|
89
|
+graph_title rspamd bayes statfiles
|
|
90
|
+graph_args --base 1000 -l 0
|
|
91
|
+graph_scale yes
|
|
92
|
+graph_vlabel learned mails''')
|
|
93
|
+ for stat in data['statfiles']:
|
|
94
|
+ sym = stat['symbol']
|
|
95
|
+ print(f'learned_{sym}.label {sym} learned')
|
|
96
|
+ print(f'users_{sym}.label {sym} users')
|
|
97
|
+ print()
|
|
98
|
+
|
|
99
|
+ print('''multigraph rspamd_fuzzy_hash
|
|
100
|
+graph_title rspamd fuzzy hases storage
|
|
101
|
+graph_args --base 1000 -l 0
|
|
102
|
+graph_scale yes
|
|
103
|
+graph_vlabel hashes''')
|
|
104
|
+ for storage in data['fuzzy_hashes']:
|
|
105
|
+ storage_name = storage2name(storage)
|
|
106
|
+ print(f'{storage_name}.label {storage}')
|
|
107
|
+ exit(0)
|
|
108
|
+
|
|
109
|
+print('multigraph rspamd_actions')
|
|
110
|
+for action, value in data['actions'].items():
|
|
111
|
+ print('%s.value %d' % (action.replace(' ', '_'), value))
|
|
112
|
+print('scanned.value %d' % data['scanned'])
|
|
113
|
+print('learned.value %d' % data['learned'])
|
|
114
|
+
|
|
115
|
+print('multigraph rspamd_result')
|
|
116
|
+print('spam.value %d' % data['spam_count'])
|
|
117
|
+print('ham.value %d' % data['ham_count'])
|
|
118
|
+
|
|
119
|
+print('multigraph rspamd_scantime')
|
|
120
|
+scantimes = [float(t) for t in data['scan_times'] if t]
|
|
121
|
+scantime = sum(scantimes) / len(scantimes)
|
|
122
|
+print('scantime.value %f' % scantime)
|
|
123
|
+
|
|
124
|
+print('multigraph rspamd_uptime')
|
|
125
|
+print('uptime.value %f' % (data['uptime']/(3600*24)))
|
|
126
|
+
|
|
127
|
+print('multigraph rspamd_memory')
|
|
128
|
+print('memory.value %d' % data['bytes_allocated'])
|
|
129
|
+
|
|
130
|
+print('multigraph rspamd_connections')
|
|
131
|
+print('connections.value %d' % data['connections'])
|
|
132
|
+
|
|
133
|
+print('multigraph rspamd_ctrl_connections')
|
|
134
|
+print('connections.value %d' % data['control_connections'])
|
|
135
|
+
|
|
136
|
+print('multigraph rspamd_statfiles')
|
|
137
|
+for stat in data['statfiles']:
|
|
138
|
+ sym = stat['symbol']
|
|
139
|
+ print(f'learned_{sym}.value %d' % stat['revision'])
|
|
140
|
+ print(f'users_{sym}.value %d' % stat['users'])
|
|
141
|
+
|
|
142
|
+print('multigraph rspamd_fuzzy_hash')
|
|
143
|
+for storage, count in data['fuzzy_hashes'].items():
|
|
144
|
+ storage_name = storage2name(storage)
|
|
145
|
+ print(f'{storage_name}.value %d' % count)
|