]> arthur.barton.de Git - netdata.git/blob - python.d/nsd.chart.py
nsd plugin
[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         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:
92             return None