-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectd-varnishstat.py
executable file
·34 lines (26 loc) · 1.05 KB
/
collectd-varnishstat.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
#!/usr/bin/python
import collectd
import json
import socket
from subprocess import check_output
metrics = [('cache_hit', 'MAIN.cache_hit'),
('cache_hitpass', 'MAIN.cache_hitpass'),
('cache_miss', 'MAIN.cache_miss'),
('backend_conn', 'MAIN.backend_conn'),
('backend_unhealthy', 'MAIN.backend_unhealthy'),
('backend_busy', 'MAIN.backend_busy'),
('backend_fail', 'MAIN.backend_fail'),
('backend_recycle', 'MAIN.backend_recycle'),
('backend_retry', 'MAIN.backend_retry'),
('backend_req', 'MAIN.backend_req'),
('client_bodybytes', 'MAIN.s_req_bodybytes')]
host = socket.gethostname()
def send_stats():
varnish_stats = json.loads(check_output(['/usr/bin/varnishstat', '-j','-f', 'MAIN.*']))
for m,v in metrics:
vl = collectd.Values(type='counter')
vl.host = host
vl.plugin = "varnishstat"
vl.plugin_instance = m
vl.dispatch(values = [varnish_stats[v]['value']], time=0)
collectd.register_read(send_stats,interval=5)