bind_rndc_plugin: python 2.6 compatibility fix
Ilya committed
Feb 20, 2017 at 22:27 UTC
5a727706c88f3bc32530b045ca291d57f79fbefe
1 file changed
+12
-13
python.d/bind_rndc.chart.py
+12
-13
@@ -50,15 +50,15 @@ class Service(SimpleService):
50
if not run_rndc.returncode:
51
# 'rndc' was found, stats file is exist and readable and we can run 'rndc stats'. Lets go!
52
self.create_charts()
53
-
53
+
54
# BIND APPEND dump on every run 'rndc stats'
55
# that is why stats file size can be VERY large if update_interval too small
56
dump_size_24hr = round(86400 / self.update_every * (int(size_after) - int(size_before)) / 1048576, 3)
57
-
57
+
58
# If update_every too small we should WARN user
59
if self.update_every < 30:
60
self.info('Update_every %s is NOT recommended for use. Increase the value to > 30' % self.update_every)
61
-
61
+
62
self.info('With current update_interval it will be + %s MB every 24hr. '
63
'Don\'t forget to create logrotate conf file for %s' % (dump_size_24hr, self.named_stats_path))
64
@@ -77,12 +77,11 @@ class Service(SimpleService):
77
named.stats file size
78
)
79
"""
80
-
80
try:
81
current_size = getsize(self.named_stats_path)
82
except OSError:
83
return None, None
85
-
84
+
85
run_rndc = Popen([self.rndc, 'stats'], shell=False)
86
run_rndc.wait()
87
@@ -110,7 +109,7 @@ class Service(SimpleService):
109
return None
110
111
rndc_stats = dict()
113
-
112
+
113
# Result: dict.
114
# topic = Cache DB RRsets; body = A 178303 NS 86790 ... ; desc = A; value = 178303
115
# {'Cache DB RRsets': [('A', 178303), ('NS', 286790), ...],
@@ -119,14 +118,14 @@ class Service(SimpleService):
118
for regex in self.regex_options:
119
rndc_stats.update({topic: [(desc, int(value)) for value, desc in self.regex_values.findall(body)]
120
for topic, body in findall(regex, raw_data)})
122
-
121
+
122
nms = dict(rndc_stats.get('Name Server Statistics', []))
123
125
- inc_queries = {'i' + k: 0 for k in QUERIES}
126
- inc_queries.update({'i' + k: v for k, v in rndc_stats.get('Incoming Queries', [])})
127
- out_queries = {'o' + k: 0 for k in QUERIES}
128
- out_queries.update({'o' + k: v for k, v in rndc_stats.get('Outgoing Queries', [])})
129
-
124
+ inc_queries = dict([('i' + k, 0) for k in QUERIES])
125
+ inc_queries.update(dict([('i' + k, v) for k, v in rndc_stats.get('Incoming Queries', [])]))
126
+ out_queries = dict([('o' + k, 0) for k in QUERIES])
127
+ out_queries.update(dict([('o' + k, v) for k, v in rndc_stats.get('Outgoing Queries', [])]))
128
+
129
to_netdata = dict()
130
to_netdata['requests'] = sum([v for k, v in nms.items() if 'request' in k and 'received' in k])
131
to_netdata['responses'] = sum([v for k, v in nms.items() if 'responses' in k and 'sent' in k])
@@ -140,7 +139,7 @@ class Service(SimpleService):
139
to_netdata['duplicate'] = nms.get('duplicate queries received', 0)
140
to_netdata['rejections'] = nms.get('recursive queries rejected', 0)
141
to_netdata['stats_size'] = size
143
-
142
+
143
to_netdata.update(inc_queries)
144
to_netdata.update(out_queries)
145
return to_netdata