nsd.chart.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. # Description: NSD `nsd-control stats_noreset` netdata python.d module
  3. # Author: <383c57 at gmail.com>
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. import re
  6. from bases.FrameworkServices.ExecutableService import ExecutableService
  7. # default module values (can be overridden per job in `config`)
  8. priority = 60000
  9. retries = 5
  10. update_every = 30
  11. # charts order (can be overridden if you want less charts, or different order)
  12. ORDER = ['queries', 'zones', 'protocol', 'type', 'transfer', 'rcode']
  13. CHARTS = {
  14. 'queries': {
  15. 'options': [None, 'queries', 'queries/s', 'queries', 'nsd.queries', 'line'],
  16. 'lines': [
  17. ['num_queries', 'queries', 'incremental']
  18. ]
  19. },
  20. 'zones': {
  21. 'options': [None, 'zones', 'zones', 'zones', 'nsd.zones', 'stacked'],
  22. 'lines': [
  23. ['zone_master', 'master', 'absolute'],
  24. ['zone_slave', 'slave', 'absolute']
  25. ]
  26. },
  27. 'protocol': {
  28. 'options': [None, 'protocol', 'queries/s', 'protocol', 'nsd.protocols', 'stacked'],
  29. 'lines': [
  30. ['num_udp', 'udp', 'incremental'],
  31. ['num_udp6', 'udp6', 'incremental'],
  32. ['num_tcp', 'tcp', 'incremental'],
  33. ['num_tcp6', 'tcp6', 'incremental']
  34. ]
  35. },
  36. 'type': {
  37. 'options': [None, 'query type', 'queries/s', 'query type', 'nsd.type', 'stacked'],
  38. 'lines': [
  39. ['num_type_A', 'A', 'incremental'],
  40. ['num_type_NS', 'NS', 'incremental'],
  41. ['num_type_CNAME', 'CNAME', 'incremental'],
  42. ['num_type_SOA', 'SOA', 'incremental'],
  43. ['num_type_PTR', 'PTR', 'incremental'],
  44. ['num_type_HINFO', 'HINFO', 'incremental'],
  45. ['num_type_MX', 'MX', 'incremental'],
  46. ['num_type_NAPTR', 'NAPTR', 'incremental'],
  47. ['num_type_TXT', 'TXT', 'incremental'],
  48. ['num_type_AAAA', 'AAAA', 'incremental'],
  49. ['num_type_SRV', 'SRV', 'incremental'],
  50. ['num_type_TYPE255', 'ANY', 'incremental']
  51. ]
  52. },
  53. 'transfer': {
  54. 'options': [None, 'transfer', 'queries/s', 'transfer', 'nsd.transfer', 'stacked'],
  55. 'lines': [
  56. ['num_opcode_NOTIFY', 'NOTIFY', 'incremental'],
  57. ['num_type_TYPE252', 'AXFR', 'incremental']
  58. ]
  59. },
  60. 'rcode': {
  61. 'options': [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. def _get_data(self):
  82. lines = self._get_raw_data()
  83. if not lines:
  84. return None
  85. r = self.regex
  86. stats = dict((k.replace('.', '_'), int(v))
  87. for k, v in r.findall(''.join(lines)))
  88. stats.setdefault('num_opcode_NOTIFY', 0)
  89. stats.setdefault('num_type_TYPE252', 0)
  90. stats.setdefault('num_type_TYPE255', 0)
  91. return stats