bundlewrap/bundles/rspamd/files/telegraf-rspamd-plugin

45 lines
1 KiB
Text
Raw Normal View History

2021-08-23 20:19:31 +00:00
#!/usr/bin/env python3
from sys import argv, stderr
2023-02-05 16:30:58 +00:00
from requests import get
2021-08-23 20:19:31 +00:00
try:
r = get('http://127.0.0.1:11334/stat')
r.raise_for_status()
json = r.json()
actions = set()
for k, v in json['actions'].items():
actions.add('{}={}i'.format(k.replace(' ', '_'), v))
print('rspamd_actions {}'.format(','.join(sorted(actions))))
stats = set()
for i in {
'scanned',
'learned',
'spam_count',
'ham_count',
'connections',
'control_connections',
'pools_allocated',
'pools_freed',
'bytes_allocated',
'chunks_allocated',
'shared_chunks_allocated',
'chunks_freed',
'chunks_oversized',
'fragmented',
'total_learns',
}:
stats.add('{}={}i'.format(i, json[i]))
print('rspamd_stats {}'.format(','.join(sorted(stats))))
for domain, value in json['fuzzy_hashes'].items():
print('rspamd_fuzzy,domain={} value={}i'.format(domain, value))
except Exception as e:
print(repr(e), file=stderr)