Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerDNS recursor check #2108

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions checks.d/powerdns-recursor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Datadog
from checks import AgentCheck

# Other
import simplejson as json
import requests
from collections import namedtuple

class PdnsChecks(AgentCheck):


def _get_pdns_stats(self, instance):
config = self._get_config(instance)
url = config.pdns_url + ':' + str(config.port) + "/servers/localhost/statistics"
headers = {"X-API-Key" : config.api_key}
request = requests.get(url, headers=headers)
result = json.loads(request.text)
return result
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of a result ? How many stats would be returned most of the time ?


def check(self, instance):
stats = self._get_pdns_stats(instance)
for stat in stats:
self.gauge('pdns.' + stat['name'], stat['value'])

def _get_config(self, instance):
required = ['pdns_url', 'port', 'api_key']
for param in required:
if not instance.get(param):
raise Exception("powerdns-recursor instance missing %s. Skipping." % (param))

pdns_url = instance.get('pdns_url')
port = instance.get('port')
api_key = instance.get('api_key')

Config = namedtuple('Config', [
'pdns_url',
'port',
'api_key']
)

return Config(pdns_url, port, api_key)
6 changes: 6 additions & 0 deletions conf.d/powerdns-recursor.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
init_config:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but you should remove the .j2 file extension.


instances:
- pdns_url: http://127.0.0.1
port: 8082
api_key: pdns_api_key