@cryptotaxi247 / netdata-1 / commits / c63e93506

modified: python.d/nsd.chart.py

- fix: dict comprehension in python2.6 - clean: `try except` - change: replace the . with _ at the dimension id

383c57 committed Mar 7, 2017 at 20:25 UTC c63e935063391d88d9b6c7483a0b502c3ace4443
1 file changed +38 -37
python.d/nsd.chart.py
+38 -37
@@ -19,54 +19,54 @@ CHARTS = {
19 'options': [
20 None, "queries", 'queries/s', 'queries', 'nsd.queries', 'line'],
21 'lines': [
22 - ['num.queries', 'queries', 'incremental'],]},
22 + ['num_queries', 'queries', 'incremental'],]},
23 'zones': {
24 'options': [
25 None, "zones", 'zones', 'zones', 'nsd.zones', 'stacked'],
26 'lines': [
27 - ['zone.master', 'master', 'absolute'],
28 - ['zone.slave', 'slave', 'absolute'],]},
27 + ['zone_master', 'master', 'absolute'],
28 + ['zone_slave', 'slave', 'absolute'],]},
29 'protocol': {
30 'options': [
31 None, "protocol", 'queries/s', 'protocol', 'nsd.protocols', 'stacked'],
32 'lines': [
33 - ['num.udp', 'udp', 'incremental'],
34 - ['num.udp6', 'udp6', 'incremental'],
35 - ['num.tcp', 'tcp', 'incremental'],
36 - ['num.tcp6', 'tcp6', 'incremental'],]},
33 + ['num_udp', 'udp', 'incremental'],
34 + ['num_udp6', 'udp6', 'incremental'],
35 + ['num_tcp', 'tcp', 'incremental'],
36 + ['num_tcp6', 'tcp6', 'incremental'],]},
37 'type': {
38 'options': [
39 None, "query type", 'queries/s', 'query type', 'nsd.type', 'stacked'],
40 'lines': [
41 - ['num.type.A', 'A', 'incremental'],
42 - ['num.type.NS', 'NS', 'incremental'],
43 - ['num.type.CNAME', 'CNAME', 'incremental'],
44 - ['num.type.SOA', 'SOA', 'incremental'],
45 - ['num.type.PTR', 'PTR', 'incremental'],
46 - ['num.type,HINFO', 'HINFO', 'incremental'],
47 - ['num.type.MX', 'MX', 'incremental'],
48 - ['num.type.NAPTR', 'NAPTR', 'incremental'],
49 - ['num.type.TXT', 'TXT', 'incremental'],
50 - ['num.type.AAAA', 'AAAA', 'incremental'],
51 - ['num.type.SRV', 'SRV', 'incremental'],
52 - ['num.type.TYPE255', 'ANY', 'incremental'],]},
41 + ['num_type_A', 'A', 'incremental'],
42 + ['num_type_NS', 'NS', 'incremental'],
43 + ['num_type_CNAME', 'CNAME', 'incremental'],
44 + ['num_type_SOA', 'SOA', 'incremental'],
45 + ['num_type_PTR', 'PTR', 'incremental'],
46 + ['num_type_HINFO', 'HINFO', 'incremental'],
47 + ['num_type_MX', 'MX', 'incremental'],
48 + ['num_type_NAPTR', 'NAPTR', 'incremental'],
49 + ['num_type_TXT', 'TXT', 'incremental'],
50 + ['num_type_AAAA', 'AAAA', 'incremental'],
51 + ['num_type_SRV', 'SRV', 'incremental'],
52 + ['num_type_TYPE255', 'ANY', 'incremental'],]},
53 'transfer': {
54 'options': [
55 None, "transfer", 'queries/s', 'transfer', 'nsd.transfer', 'stacked'],
56 'lines': [
57 - ['num.opcode.NOTIFY', 'NOTIFY', 'incremental'],
58 - ['num.type.TYPE252', 'AXFR', 'incremental'],]},
57 + ['num_opcode_NOTIFY', 'NOTIFY', 'incremental'],
58 + ['num_type_TYPE252', 'AXFR', 'incremental'],]},
59 'rcode': {
60 'options': [
61 None, "return code", 'queries/s', 'return code', 'nsd.rcode', 'stacked'],
62 'lines': [
63 - ['num.rcode.NOERROR', 'NOERROR', 'incremental'],
64 - ['num.rcode.FORMERR', 'FORMERR', 'incremental'],
65 - ['num.rcode.SERVFAIL', 'SERVFAIL', 'incremental'],
66 - ['num.rcode.NXDOMAIN', 'NXDOMAIN', 'incremental'],
67 - ['num.rcode.NOTIMP', 'NOTIMP', 'incremental'],
68 - ['num.rcode.REFUSED', 'REFUSED', 'incremental'],
69 - ['num.rcode.YXDOMAIN', 'YXDOMAIN', 'incremental'],]}
63 + ['num_rcode_NOERROR', 'NOERROR', 'incremental'],
64 + ['num_rcode_FORMERR', 'FORMERR', 'incremental'],
65 + ['num_rcode_SERVFAIL', 'SERVFAIL', 'incremental'],
66 + ['num_rcode_NXDOMAIN', 'NXDOMAIN', 'incremental'],
67 + ['num_rcode_NOTIMP', 'NOTIMP', 'incremental'],
68 + ['num_rcode_REFUSED', 'REFUSED', 'incremental'],
69 + ['num_rcode_YXDOMAIN', 'YXDOMAIN', 'incremental'],]}
70 }
71
72
@@ -80,13 +80,14 @@ class Service(ExecutableService):
80 self.regex = re.compile(r'([A-Za-z0-9.]+)=(\d+)')
81
82 def _get_data(self):
83 - try:
84 - lines = self._get_raw_data()
85 - r = self.regex
86 - stats = {k: int(v) for k, v in r.findall(''.join(lines))}
87 - stats.setdefault('num.opcode.NOTIFY', 0)
88 - stats.setdefault('num.type.TYPE252', 0)
89 - stats.setdefault('num.type.TYPE255', 0)
90 - return stats
91 - except Exception:
83 + lines = self._get_raw_data()
84 + if not lines:
85 return None
86 +
87 + r = self.regex
88 + stats = dict((k.replace('.', '_'), int(v))
89 + for k, v in r.findall(''.join(lines)))
90 + stats.setdefault('num.opcode.NOTIFY', 0)
91 + stats.setdefault('num.type.TYPE252', 0)
92 + stats.setdefault('num.type.TYPE255', 0)
93 + return stats