nsd.chart.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. update_every = 30
  8. NSD_CONTROL_COMMAND = 'nsd-control stats_noreset'
  9. REGEX = re.compile(r'([A-Za-z0-9.]+)=(\d+)')
  10. ORDER = [
  11. 'queries',
  12. 'zones',
  13. 'protocol',
  14. 'type',
  15. 'transfer',
  16. 'rcode',
  17. ]
  18. CHARTS = {
  19. 'queries': {
  20. 'options': [None, 'queries', 'queries/s', 'queries', 'nsd.queries', 'line'],
  21. 'lines': [
  22. ['num_queries', 'queries', 'incremental']
  23. ]
  24. },
  25. 'zones': {
  26. 'options': [None, 'zones', 'zones', 'zones', 'nsd.zones', 'stacked'],
  27. 'lines': [
  28. ['zone_master', 'master', 'absolute'],
  29. ['zone_slave', 'slave', 'absolute']
  30. ]
  31. },
  32. 'protocol': {
  33. 'options': [None, 'protocol', 'queries/s', 'protocol', 'nsd.protocols', 'stacked'],
  34. 'lines': [
  35. ['num_udp', 'udp', 'incremental'],
  36. ['num_udp6', 'udp6', 'incremental'],
  37. ['num_tcp', 'tcp', 'incremental'],
  38. ['num_tcp6', 'tcp6', 'incremental']
  39. ]
  40. },
  41. 'type': {
  42. 'options': [None, 'query type', 'queries/s', 'query type', 'nsd.type', 'stacked'],
  43. 'lines': [
  44. ['num_type_A', 'A', 'incremental'],
  45. ['num_type_NS', 'NS', 'incremental'],
  46. ['num_type_CNAME', 'CNAME', 'incremental'],
  47. ['num_type_SOA', 'SOA', 'incremental'],
  48. ['num_type_PTR', 'PTR', 'incremental'],
  49. ['num_type_HINFO', 'HINFO', 'incremental'],
  50. ['num_type_MX', 'MX', 'incremental'],
  51. ['num_type_NAPTR', 'NAPTR', 'incremental'],
  52. ['num_type_TXT', 'TXT', 'incremental'],
  53. ['num_type_AAAA', 'AAAA', 'incremental'],
  54. ['num_type_SRV', 'SRV', 'incremental'],
  55. ['num_type_TYPE255', 'ANY', 'incremental']
  56. ]
  57. },
  58. 'transfer': {
  59. 'options': [None, 'transfer', 'queries/s', 'transfer', 'nsd.transfer', 'stacked'],
  60. 'lines': [
  61. ['num_opcode_NOTIFY', 'NOTIFY', 'incremental'],
  62. ['num_type_TYPE252', 'AXFR', 'incremental']
  63. ]
  64. },
  65. 'rcode': {
  66. 'options': [None, 'return code', 'queries/s', 'return code', 'nsd.rcode', 'stacked'],
  67. 'lines': [
  68. ['num_rcode_NOERROR', 'NOERROR', 'incremental'],
  69. ['num_rcode_FORMERR', 'FORMERR', 'incremental'],
  70. ['num_rcode_SERVFAIL', 'SERVFAIL', 'incremental'],
  71. ['num_rcode_NXDOMAIN', 'NXDOMAIN', 'incremental'],
  72. ['num_rcode_NOTIMP', 'NOTIMP', 'incremental'],
  73. ['num_rcode_REFUSED', 'REFUSED', 'incremental'],
  74. ['num_rcode_YXDOMAIN', 'YXDOMAIN', 'incremental']
  75. ]
  76. }
  77. }
  78. class Service(ExecutableService):
  79. def __init__(self, configuration=None, name=None):
  80. ExecutableService.__init__(self, configuration=configuration, name=name)
  81. self.order = ORDER
  82. self.definitions = CHARTS
  83. self.command = NSD_CONTROL_COMMAND
  84. def _get_data(self):
  85. lines = self._get_raw_data()
  86. if not lines:
  87. return None
  88. stats = dict(
  89. (k.replace('.', '_'), int(v)) for k, v in REGEX.findall(''.join(lines))
  90. )
  91. stats.setdefault('num_opcode_NOTIFY', 0)
  92. stats.setdefault('num_type_TYPE252', 0)
  93. stats.setdefault('num_type_TYPE255', 0)
  94. return stats