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

Add Powerdns Recursor input plugin #812

Closed
descrepes opened this issue Mar 8, 2016 · 6 comments
Closed

Add Powerdns Recursor input plugin #812

descrepes opened this issue Mar 8, 2016 · 6 comments
Labels
feature request Requests for new plugin and for new features to existing plugins
Milestone

Comments

@descrepes
Copy link

Hi,

The actual Powerdns input plugin seems to be available for the "pdns_server" socket only.
It would be awesome if it could collect from the "pdns_recursor" socket :p

Thx a lot !

@sparrc sparrc added the help wanted Request for community participation, code, contribution label Mar 24, 2016
@alexzorin
Copy link
Contributor

+1 would be nice.

rec_control in PowerDNS Recursor 4.x appears to use unix datagram socket that I can't quite wrap my head around from Go (unixgram times out, need to look at rec_control implementation more closely):

https://github.com/PowerDNS/pdns/blob/09cc8c7a36414ed93dd3b67c4767298da7c2f10d/pdns/rec_channel.cc#L60

socket(PF_LOCAL, SOCK_DGRAM, 0)         = 3
fcntl(3, F_GETFD)                       = 0
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
gettimeofday({1473131680, 118010}, NULL) = 0
open("/var/run/lsocknyxXzx", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
unlink("/var/run/lsocknyxXzx")          = 0
bind(3, {sa_family=AF_LOCAL, sun_path="/var/run/lsocknyxXzx"}, 110) = 0
chmod("/var/run/lsocknyxXzx", 0666)     = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/pdns_recursor.controlsocket"}, 110) = 0
sendto(3, "get-all", 7, 0, NULL, 0)     = 7
...

and also the output is with new lines and field delimited by whitespace:

unauthorized-tcp        0
unauthorized-udp        0
unexpected-packets      0
unreachables    0
uptime  4625
user-msec       209

@danielnelson danielnelson changed the title Feature request: Powerdns Recursor input plugin Add Powerdns Recursor input plugin Aug 12, 2017
@danielnelson danielnelson added feature request Requests for new plugin and for new features to existing plugins and removed plugin request labels Aug 12, 2017
@ahupowerdns
Copy link

Hi - there is an API to retrieve these metrics now, please see https://doc.powerdns.com/authoritative/common/api/endpoint-statistics.html
Is that helpful?
This works on all PowerDNS products.

@mikalsande
Copy link

I needed to get metrics from pdns recursor into influx and found this post. Using the API works well with the exec input. Its not pretty, but it works. I even got my Lua counters in there :)

[[inputs.exec]]
  commands = [ "/bin/sh /etc/telegraf/pdns-recursor.sh" ]
  timeout = "5s"
  name_suffix = "_pdns"
  data_format = "json"

/etc/telegraf/pdns-recursor.sh
/bin/curl -s -H 'X-API-Key: <API key>' http://127.0.0.1:8082/api/v1/servers/localhost/statistics | jq 'reduce .[] as $item ({}; . + { ($item.name): ($item.value|tonumber)})'

@dupondje
Copy link
Contributor

Merge request open for this:
#4545

@danielnelson danielnelson removed the help wanted Request for community participation, code, contribution label Apr 24, 2019
@danielnelson danielnelson added this to the 1.11.0 milestone Apr 24, 2019
@danielnelson
Copy link
Contributor

Closed in #4545

@dmgeurts
Copy link

dmgeurts commented Apr 22, 2022

/etc/telegraf/pdns-recursor.sh
/bin/curl -s -H 'X-API-Key: <API key>' http://127.0.0.1:8082/api/v1/servers/localhost/statistics | jq 'reduce .[] as $item ({}; . + { ($item.name): ($item.value|tonumber)})'

The above no longer works due to nested data, the following works for me (and can probably be improved upon):

curl -s -H 'X-API-Key: <API key>' http://127.0.0.1:8082/api/v1/servers/localhost/statistics | jq 'reduce .[] as $item ({}; . + { ($item.name): ($item.value)})' | jq 'to_entries | map(if (.value | type) == "string" then .value |= tonumber else .key as $key | .value[] | .name |= $key+"."+. | .value |= tonumber end) | from_entries'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
Development

No branches or pull requests

8 participants