forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvarnish.py
More file actions
executable file
·43 lines (32 loc) · 1.01 KB
/
varnish.py
File metadata and controls
executable file
·43 lines (32 loc) · 1.01 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
43
#!/usr/bin/env python
import subprocess
import sys
import time
command = "/usr/bin/varnishstat -1 | awk '{print $1,$2}'"
def get_varnish_metrics():
try:
status = subprocess.check_output(command, shell=True)
m = {}
for line in status.splitlines():
name = line.split()[0].lower().replace('(', '_').replace(')', '_').replace(',,', '_')
m[name] = line.split()[1]
return m
except Exception, e:
print "Plugin Failed! %s" % e
sys.exit(2)
# rate calculation
time_between = 5
metrics_before = get_varnish_metrics()
time.sleep(time_between)
metrics = get_varnish_metrics()
metric_rates = {}
for metric, value in metrics.iteritems():
if value > metrics_before[metric]:
metric_rates[metric + '_per_sec'] = (int(value) - int(metrics_before[metric])) / time_between
metrics.update(metric_rates)
# print nagios perf data and exit
output = "OK | "
for k, v in metrics.iteritems():
output += str(k) + '=' + str(v) + ';;;; '
print output
sys.exit(0)