-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_unbound.py
47 lines (39 loc) · 1.78 KB
/
check_unbound.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
import subprocess
import re
import sys
'''
spitefulgrog - Spirit Scripts
'''
process = subprocess.Popen(['sudo', 'unbound-control', 'stats'], stdout=subprocess.PIPE)
stats = {}
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
if re.search('thread.', output.strip()) or re.search('total.', output.strip()):
newthread = output.strip().split('.')[0]
if not newthread in stats:
stats.update({newthread : []})
if re.search('.num.queries.', output.strip()):
queries = output.strip().split('=')[-1]
thread = output.strip().split('.')[0]
stats[thread].insert(0, queries)
elif re.search('.num.cachehits.', output.strip()):
cachehits = output.strip().split('=')[-1]
thread = output.strip().split('.')[0]
stats[thread].insert(1, cachehits)
elif re.search('.num.cachemiss.', output.strip()):
cachemiss = output.strip().split('=')[-1]
thread = output.strip().split('.')[0]
stats[thread].insert(2, cachemiss)
output = "Stats stored"
perfdata = "| "
index = len(stats) - 1
perfdata = perfdata + "index=" + str(index) + " "
for key, value in stats.iteritems():
perfdata = perfdata + str(key) + "_queries" + "=" + str(value[0]) + " " + str(key) + "_cachehits" + "=" + str(value[1]) + " " \
+ str(key) + "_cachemiss" + "=" + str(value[2]) + " "
print output + perfdata
sys.exit(0)