]> arthur.barton.de Git - netdata.git/blob - python.d/nsd.chart.py
added netfilter expectations
[netdata.git] / python.d / nsd.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: NSD `nsd-control stats_noreset` netdata python.d module
3 # Author: <383c57 at gmail.com>
4
5
6 from base import ExecutableService
7 import re
8
9 # default module values (can be overridden per job in `config`)
10 priority = 60000
11 retries = 5
12 update_every = 30
13
14 # charts order (can be overridden if you want less charts, or different order)
15 ORDER = ['queries', 'zones', 'protocol', 'type', 'transfer', 'rcode']
16
17 CHARTS = {
18     'queries': {
19         'options': [
20             None, "queries", 'queries/s', 'queries', 'nsd.queries', 'line'],
21         'lines': [
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'],]},
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'],]},
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'],]},
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'],]},
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'],]}
70 }
71
72
73 class Service(ExecutableService):
74     def __init__(self, configuration=None, name=None):
75         ExecutableService.__init__(
76             self, configuration=configuration, name=name)
77         self.command = "nsd-control stats_noreset"
78         self.order = ORDER
79         self.definitions = CHARTS
80         self.regex = re.compile(r'([A-Za-z0-9.]+)=(\d+)')
81
82     def _get_data(self):
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