powerdns.chart.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # -*- coding: utf-8 -*-
  2. # Description: powerdns netdata python.d module
  3. # Author: Ilya Mashchenko (ilyam8)
  4. # Author: Luke Whitworth
  5. # SPDX-License-Identifier: GPL-3.0-or-later
  6. from json import loads
  7. from bases.FrameworkServices.UrlService import UrlService
  8. ORDER = [
  9. 'questions',
  10. 'cache_usage',
  11. 'cache_size',
  12. 'latency',
  13. ]
  14. CHARTS = {
  15. 'questions': {
  16. 'options': [None, 'PowerDNS Queries and Answers', 'count', 'questions', 'powerdns.questions', 'line'],
  17. 'lines': [
  18. ['udp-queries', None, 'incremental'],
  19. ['udp-answers', None, 'incremental'],
  20. ['tcp-queries', None, 'incremental'],
  21. ['tcp-answers', None, 'incremental']
  22. ]
  23. },
  24. 'cache_usage': {
  25. 'options': [None, 'PowerDNS Cache Usage', 'count', 'cache', 'powerdns.cache_usage', 'line'],
  26. 'lines': [
  27. ['query-cache-hit', None, 'incremental'],
  28. ['query-cache-miss', None, 'incremental'],
  29. ['packetcache-hit', 'packet-cache-hit', 'incremental'],
  30. ['packetcache-miss', 'packet-cache-miss', 'incremental']
  31. ]
  32. },
  33. 'cache_size': {
  34. 'options': [None, 'PowerDNS Cache Size', 'count', 'cache', 'powerdns.cache_size', 'line'],
  35. 'lines': [
  36. ['query-cache-size', None, 'absolute'],
  37. ['packetcache-size', 'packet-cache-size', 'absolute'],
  38. ['key-cache-size', None, 'absolute'],
  39. ['meta-cache-size', None, 'absolute']
  40. ]
  41. },
  42. 'latency': {
  43. 'options': [None, 'PowerDNS Latency', 'microseconds', 'latency', 'powerdns.latency', 'line'],
  44. 'lines': [
  45. ['latency', None, 'absolute']
  46. ]
  47. }
  48. }
  49. RECURSOR_ORDER = ['questions-in', 'questions-out', 'answer-times', 'timeouts', 'drops', 'cache_usage', 'cache_size']
  50. RECURSOR_CHARTS = {
  51. 'questions-in': {
  52. 'options': [None, 'PowerDNS Recursor Questions In', 'count', 'questions', 'powerdns_recursor.questions-in',
  53. 'line'],
  54. 'lines': [
  55. ['questions', None, 'incremental'],
  56. ['ipv6-questions', None, 'incremental'],
  57. ['tcp-questions', None, 'incremental']
  58. ]
  59. },
  60. 'questions-out': {
  61. 'options': [None, 'PowerDNS Recursor Questions Out', 'count', 'questions', 'powerdns_recursor.questions-out',
  62. 'line'],
  63. 'lines': [
  64. ['all-outqueries', None, 'incremental'],
  65. ['ipv6-outqueries', None, 'incremental'],
  66. ['tcp-outqueries', None, 'incremental'],
  67. ['throttled-outqueries', None, 'incremental']
  68. ]
  69. },
  70. 'answer-times': {
  71. 'options': [None, 'PowerDNS Recursor Answer Times', 'count', 'performance', 'powerdns_recursor.answer-times',
  72. 'line'],
  73. 'lines': [
  74. ['answers-slow', None, 'incremental'],
  75. ['answers0-1', None, 'incremental'],
  76. ['answers1-10', None, 'incremental'],
  77. ['answers10-100', None, 'incremental'],
  78. ['answers100-1000', None, 'incremental']
  79. ]
  80. },
  81. 'timeouts': {
  82. 'options': [None, 'PowerDNS Recursor Questions Time', 'count', 'performance', 'powerdns_recursor.timeouts',
  83. 'line'],
  84. 'lines': [
  85. ['outgoing-timeouts', None, 'incremental'],
  86. ['outgoing4-timeouts', None, 'incremental'],
  87. ['outgoing6-timeouts', None, 'incremental']
  88. ]
  89. },
  90. 'drops': {
  91. 'options': [None, 'PowerDNS Recursor Drops', 'count', 'performance', 'powerdns_recursor.drops', 'line'],
  92. 'lines': [
  93. ['over-capacity-drops', None, 'incremental']
  94. ]
  95. },
  96. 'cache_usage': {
  97. 'options': [None, 'PowerDNS Recursor Cache Usage', 'count', 'cache', 'powerdns_recursor.cache_usage', 'line'],
  98. 'lines': [
  99. ['cache-hits', None, 'incremental'],
  100. ['cache-misses', None, 'incremental'],
  101. ['packetcache-hits', 'packet-cache-hit', 'incremental'],
  102. ['packetcache-misses', 'packet-cache-miss', 'incremental']
  103. ]
  104. },
  105. 'cache_size': {
  106. 'options': [None, 'PowerDNS Recursor Cache Size', 'count', 'cache', 'powerdns_recursor.cache_size', 'line'],
  107. 'lines': [
  108. ['cache-entries', None, 'absolute'],
  109. ['packetcache-entries', None, 'absolute'],
  110. ['negcache-entries', None, 'absolute']
  111. ]
  112. }
  113. }
  114. class Service(UrlService):
  115. def __init__(self, configuration=None, name=None):
  116. UrlService.__init__(self, configuration=configuration, name=name)
  117. self.order = ORDER
  118. self.definitions = CHARTS
  119. self.url = configuration.get('url', 'http://127.0.0.1:8081/api/v1/servers/localhost/statistics')
  120. def check(self):
  121. self._manager = self._build_manager()
  122. if not self._manager:
  123. return None
  124. d = self._get_data()
  125. if not d:
  126. return False
  127. if is_recursor(d):
  128. self.order = RECURSOR_ORDER
  129. self.definitions = RECURSOR_CHARTS
  130. self.module_name = 'powerdns_recursor'
  131. return True
  132. def _get_data(self):
  133. data = self._get_raw_data()
  134. if not data:
  135. return None
  136. return dict((d['name'], d['value']) for d in loads(data))
  137. def is_recursor(d):
  138. return 'over-capacity-drops' in d and 'tcp-questions' in d