@cryptotaxi247 / netdata-1 / commits / d07f3aa1d

bind_rndc: incoming/outgoing queries charts added

Ilya committed Jan 6, 2017 at 13:19 UTC d07f3aa1dbb34ee87c564bbfdb739534e8271096
1 file changed +39 -20
python.d/bind_rndc.chart.py
+39 -20
@@ -13,6 +13,10 @@ retries = 60
13 update_every = 30
14
15 DIRECTORIES = ['/bin/', '/usr/bin/', '/sbin/', '/usr/sbin/']
16 +NMS = ['requests', 'responses', 'success', 'auth_answer', 'nonauth_answer', 'nxrrset', 'failure',
17 + 'nxdomain', 'recursion', 'duplicate', 'rejections']
18 +QUERIES = ['RESERVED0', 'A', 'NS', 'CNAME', 'SOA', 'PTR', 'MX', 'TXT', 'X25', 'AAAA', 'SRV', 'NAPTR',
19 + 'A6', 'DS', 'RRSIG', 'DNSKEY', 'SPF', 'ANY', 'DLV']
20
21
22 class Service(SimpleService):
@@ -23,7 +27,7 @@ class Service(SimpleService):
27 # self.options = ['Incoming Requests', 'Incoming Queries', 'Outgoing Queries',
28 # 'Name Server Statistics', 'Zone Maintenance Statistics', 'Resolver Statistics',
29 # 'Cache DB RRsets', 'Socket I/O Statistics']
26 - self.options = ['Name Server Statistics']
30 + self.options = ['Name Server Statistics', 'Incoming Queries', 'Outgoing Queries']
31 self.regex_options = [r'(%s(?= \+\+)) \+\+([^\+]+)' % option for option in self.options]
32 try:
33 self.rndc = [''.join([directory, 'rndc']) for directory in DIRECTORIES
@@ -32,13 +36,12 @@ class Service(SimpleService):
36 self.rndc = False
37
38 def check(self):
35 -
36 - # We cant start without 'rndc' command
39 + # We cant start without 'rndc' command
40 if not self.rndc:
41 self.error('Command "rndc" not found')
42 return False
43
41 - # We cant if stats file is not exist or not readable by netdata user
44 + # We cant start if stats file is not exist or not readable by netdata user
45 if not is_accessible(self.named_stats_path, R_OK):
46 self.error('Cannot access file %s' % self.named_stats_path)
47 return False
@@ -72,7 +75,6 @@ class Service(SimpleService):
75 return False
76
77 def _get_raw_data(self):
75 -
78 """
79 Run 'rndc stats' and read last dump from named.stats
80 :return: tuple(
@@ -102,7 +104,6 @@ class Service(SimpleService):
104 return result, current_size
105
106 def _get_data(self):
105 -
107 """
108 Parse data from _get_raw_data()
109 :return: dict
@@ -115,14 +116,23 @@ class Service(SimpleService):
116
117 rndc_stats = dict()
118
119 + # Result: dict.
120 + # topic = Cache DB RRsets; body = A 178303 NS 86790 ... ; desc = A; value = 178303
121 + # {'Cache DB RRsets': [('A', 178303), ('NS', 286790), ...],
122 + # {Incoming Queries': [('RESERVED0', 8), ('A', 4557317680), ...],
123 + # ......
124 for regex in self.regex_options:
119 - rndc_stats.update({k: [(y, int(x)) for x, y in self.regex_values.findall(v)]
120 - for k, v in findall(regex, raw_data)})
125 + rndc_stats.update({topic: [(desc, int(value)) for value, desc in self.regex_values.findall(body)]
126 + for topic, body in findall(regex, raw_data)})
127
128 nms = dict(rndc_stats.get('Name Server Statistics', []))
129
130 + inc_queries = {'i' + k: 0 for k in QUERIES}
131 + inc_queries.update({'i' + k: v for k, v in rndc_stats.get('Incoming Queries', [])})
132 + out_queries = {'o' + k: 0 for k in QUERIES}
133 + out_queries.update({'o' + k: v for k, v in rndc_stats.get('Outgoing Queries', [])})
134 +
135 to_netdata = dict()
125 -
136 to_netdata['requests'] = sum([v for k, v in nms.items() if 'request' in k and 'received' in k])
137 to_netdata['responses'] = sum([v for k, v in nms.items() if 'responses' in k and 'sent' in k])
138 to_netdata['success'] = nms.get('queries resulted in successful answer', 0)
@@ -136,26 +146,35 @@ class Service(SimpleService):
146 to_netdata['rejections'] = nms.get('recursive queries rejected', 0)
147 to_netdata['stats_size'] = size
148
149 + to_netdata.update(inc_queries)
150 + to_netdata.update(out_queries)
151 return to_netdata
152
153 def create_charts(self):
142 -
143 - self.order = ['stats_size', 'bind_stats']
154 + self.order = ['stats_size', 'bind_stats', 'incoming_q', 'outgoing_q']
155 self.definitions = {
156 'bind_stats': {
146 - 'options': [None, 'Name Server Statistics', 'stats', 'NS Statistics', 'bind_rndc.stats', 'line'],
157 + 'options': [None, 'Name Server Statistics', 'stats', 'Name Server Statistics', 'bind_rndc.stats', 'line'],
158 'lines': [
148 - ["requests", None, "incremental"], ["responses", None, "incremental"],
149 - ["success", None, "incremental"], ["auth_answer", None, "incremental"],
150 - ["nonauth_answer", None, "incremental"], ["nxrrset", None, "incremental"],
151 - ["failure", None, "incremental"], ["nxdomain", None, "incremental"],
152 - ["recursion", None, "incremental"], ["duplicate", None, "incremental"],
153 - ["rejections", None, "incremental"]
159 ]},
155 - 'stats_size': {
156 - 'options': [None, '%s file size' % split(self.named_stats_path)[1].capitalize(), 'megabyte',
160 + 'incoming_q': {
161 + 'options': [None, 'Incoming queries', 'queries','Incoming queries', 'bind_rndc.incq', 'line'],
162 + 'lines': [
163 + ]},
164 + 'outgoing_q': {
165 + 'options': [None, 'Outgoing queries', 'queries','Outgoing queries', 'bind_rndc.outq', 'line'],
166 + 'lines': [
167 + ]},
168 + 'stats_size': {
169 + 'options': [None, '%s file size' % split(self.named_stats_path)[1].capitalize(), 'megabytes',
170 '%s size' % split(self.named_stats_path)[1].capitalize(), 'bind_rndc.size', 'line'],
171 'lines': [
172 ["stats_size", None, "absolute", 1, 1048576]
173 ]}
174 }
175 + for elem in QUERIES:
176 + self.definitions['incoming_q']['lines'].append(['i' + elem, elem, 'incremental'])
177 + self.definitions['outgoing_q']['lines'].append(['o' + elem, elem, 'incremental'])
178 +
179 + for elem in NMS:
180 + self.definitions['bind_stats']['lines'].append([elem, None, 'incremental'])