1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,194 @@
# PowerDNS Recursor Input Plugin
The `powerdns_recursor` plugin gathers metrics about PowerDNS Recursor using
the unix controlsocket.
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
## Configuration
```toml @sample.conf
# Read metrics from one or many PowerDNS Recursor servers
[[inputs.powerdns_recursor]]
## Path to the Recursor control socket.
unix_sockets = ["/var/run/pdns_recursor.controlsocket"]
## Directory to create receive socket. This default is likely not writable,
## please reference the full plugin documentation for a recommended setup.
# socket_dir = "/var/run/"
## Socket permissions for the receive socket.
# socket_mode = "0666"
## The version of the PowerDNS control protocol to use. You will have to
## change this based on your PowerDNS Recursor version, see below:
## Version 1: PowerDNS <4.5.0
## Version 2: PowerDNS 4.5.0 - 4.5.11
## Version 3: PowerDNS >=4.6.0
## By default this is set to 1.
# control_protocol_version = 1
```
### Newer PowerDNS Recursor versions
By default, this plugin is compatible with PowerDNS Recursor versions older
than `4.5.0`. If you are using a newer version then you'll need to adjust the
`control_protocol_version` configuration option based on your version. For
versions between `4.5.0` and `4.5.11` set it to `2` and for versions `4.6.0`
and newer set it to `3`. If you don't, you will get an `i/o timeout` or a
`protocol wrong type for socket` error.
### Permissions
Telegraf will need read/write access to the control socket and to the
`socket_dir`. PowerDNS will need to be able to write to the `socket_dir`.
The setup described below was tested on a Debian Stretch system and may need
adapted for other systems.
First change permissions on the controlsocket in the PowerDNS recursor
configuration, usually in `/etc/powerdns/recursor.conf`:
```sh
socket-mode = 660
```
Then place the `telegraf` user into the `pdns` group:
```sh
usermod telegraf -a -G pdns
```
Since `telegraf` cannot write to to the default `/var/run` socket directory,
create a subdirectory and adjust permissions for this directory so that both
users can access it.
```sh
mkdir /var/run/pdns
chown root:pdns /var/run/pdns
chmod 770 /var/run/pdns
```
## Metrics
- powerdns_recursor
- tags:
- server
- fields:
- all-outqueries
- answers-slow
- answers0-1
- answers1-10
- answers10-100
- answers100-1000
- auth-zone-queries
- auth4-answers-slow
- auth4-answers0-1
- auth4-answers1-10
- auth4-answers10-100
- auth4-answers100-1000
- auth6-answers-slow
- auth6-answers0-1
- auth6-answers1-10
- auth6-answers10-100
- auth6-answers100-1000
- cache-entries
- cache-hits
- cache-misses
- case-mismatches
- chain-resends
- client-parse-errors
- concurrent-queries
- dlg-only-drops
- dnssec-queries
- dnssec-result-bogus
- dnssec-result-indeterminate
- dnssec-result-insecure
- dnssec-result-nta
- dnssec-result-secure
- dnssec-validations
- dont-outqueries
- ecs-queries
- ecs-responses
- edns-ping-matches
- edns-ping-mismatches
- failed-host-entries
- fd-usage
- ignored-packets
- ipv6-outqueries
- ipv6-questions
- malloc-bytes
- max-cache-entries
- max-mthread-stack
- max-packetcache-entries
- negcache-entries
- no-packet-error
- noedns-outqueries
- noerror-answers
- noping-outqueries
- nsset-invalidations
- nsspeeds-entries
- nxdomain-answers
- outgoing-timeouts
- outgoing4-timeouts
- outgoing6-timeouts
- over-capacity-drops
- packetcache-entries
- packetcache-hits
- packetcache-misses
- policy-drops
- policy-result-custom
- policy-result-drop
- policy-result-noaction
- policy-result-nodata
- policy-result-nxdomain
- policy-result-truncate
- qa-latency
- query-pipe-full-drops
- questions
- real-memory-usage
- resource-limits
- security-status
- server-parse-errors
- servfail-answers
- spoof-prevents
- sys-msec
- tcp-client-overflow
- tcp-clients
- tcp-outqueries
- tcp-questions
- throttle-entries
- throttled-out
- throttled-outqueries
- too-old-drops
- udp-in-errors
- udp-noport-errors
- udp-recvbuf-errors
- udp-sndbuf-errors
- unauthorized-tcp
- unauthorized-udp
- unexpected-packets
- unreachables
- uptime
- user-msec
- x-our-latency
- x-ourtime-slow
- x-ourtime0-1
- x-ourtime1-2
- x-ourtime16-32
- x-ourtime2-4
- x-ourtime4-8
- x-ourtime8-16
## Example Output
```text
powerdns_recursor,server=/var/run/pdns_recursor.controlsocket all-outqueries=3631810i,answers-slow=36863i,answers0-1=179612i,answers1-10=1223305i,answers10-100=1252199i,answers100-1000=408357i,auth-zone-queries=4i,auth4-answers-slow=44758i,auth4-answers0-1=59721i,auth4-answers1-10=1766787i,auth4-answers10-100=1329638i,auth4-answers100-1000=430372i,auth6-answers-slow=0i,auth6-answers0-1=0i,auth6-answers1-10=0i,auth6-answers10-100=0i,auth6-answers100-1000=0i,cache-entries=296689i,cache-hits=150654i,cache-misses=2949682i,case-mismatches=0i,chain-resends=420004i,client-parse-errors=0i,concurrent-queries=0i,dlg-only-drops=0i,dnssec-queries=152970i,dnssec-result-bogus=0i,dnssec-result-indeterminate=0i,dnssec-result-insecure=0i,dnssec-result-nta=0i,dnssec-result-secure=47i,dnssec-validations=47i,dont-outqueries=62i,ecs-queries=0i,ecs-responses=0i,edns-ping-matches=0i,edns-ping-mismatches=0i,failed-host-entries=21i,fd-usage=32i,ignored-packets=0i,ipv6-outqueries=0i,ipv6-questions=0i,malloc-bytes=0i,max-cache-entries=1000000i,max-mthread-stack=33747i,max-packetcache-entries=500000i,negcache-entries=100019i,no-packet-error=0i,noedns-outqueries=73341i,noerror-answers=25453808i,noping-outqueries=0i,nsset-invalidations=2398i,nsspeeds-entries=3966i,nxdomain-answers=3341302i,outgoing-timeouts=44384i,outgoing4-timeouts=44384i,outgoing6-timeouts=0i,over-capacity-drops=0i,packetcache-entries=78258i,packetcache-hits=25999027i,packetcache-misses=3100179i,policy-drops=0i,policy-result-custom=0i,policy-result-drop=0i,policy-result-noaction=3100336i,policy-result-nodata=0i,policy-result-nxdomain=0i,policy-result-truncate=0i,qa-latency=6553i,query-pipe-full-drops=0i,questions=29099363i,real-memory-usage=280494080i,resource-limits=0i,security-status=1i,server-parse-errors=0i,servfail-answers=304253i,spoof-prevents=0i,sys-msec=1312600i,tcp-client-overflow=0i,tcp-clients=0i,tcp-outqueries=116i,tcp-questions=133i,throttle-entries=21i,throttled-out=13296i,throttled-outqueries=13296i,too-old-drops=2i,udp-in-errors=4i,udp-noport-errors=2918i,udp-recvbuf-errors=0i,udp-sndbuf-errors=0i,unauthorized-tcp=0i,unauthorized-udp=0i,unexpected-packets=0i,unreachables=1708i,uptime=167482i,user-msec=1282640i,x-our-latency=19i,x-ourtime-slow=642i,x-ourtime0-1=3095566i,x-ourtime1-2=3401i,x-ourtime16-32=201i,x-ourtime2-4=304i,x-ourtime4-8=198i,x-ourtime8-16=24i 1533903879000000000
```

View file

@ -0,0 +1,84 @@
//go:generate ../../../tools/readme_config_includer/generator
package powerdns_recursor
import (
_ "embed"
"fmt"
"strconv"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)
//go:embed sample.conf
var sampleConfig string
const defaultTimeout = 5 * time.Second
type PowerdnsRecursor struct {
UnixSockets []string `toml:"unix_sockets"`
SocketDir string `toml:"socket_dir"`
SocketMode string `toml:"socket_mode"`
ControlProtocolVersion int `toml:"control_protocol_version"`
Log telegraf.Logger `toml:"-"`
mode uint32
gatherFromServer func(address string, acc telegraf.Accumulator) error
}
func (*PowerdnsRecursor) SampleConfig() string {
return sampleConfig
}
func (p *PowerdnsRecursor) Init() error {
if p.SocketMode != "" {
mode, err := strconv.ParseUint(p.SocketMode, 8, 32)
if err != nil {
return fmt.Errorf("could not parse socket_mode: %w", err)
}
p.mode = uint32(mode)
}
if p.SocketDir == "" {
p.SocketDir = "/var/run"
}
switch p.ControlProtocolVersion {
// We treat 0 the same as 1 since it's the default value if a user doesn't explicitly specify one.
case 0, 1:
p.gatherFromServer = p.gatherFromV1Server
case 2:
p.gatherFromServer = p.gatherFromV2Server
case 3:
p.gatherFromServer = gatherFromV3Server
default:
return fmt.Errorf("unknown control protocol version '%d', allowed values are 1, 2, 3", p.ControlProtocolVersion)
}
if len(p.UnixSockets) == 0 {
p.UnixSockets = []string{"/var/run/pdns_recursor.controlsocket"}
}
return nil
}
func (p *PowerdnsRecursor) Gather(acc telegraf.Accumulator) error {
for _, serverSocket := range p.UnixSockets {
if err := p.gatherFromServer(serverSocket, acc); err != nil {
acc.AddError(err)
}
}
return nil
}
func init() {
inputs.Add("powerdns_recursor", func() telegraf.Input {
return &PowerdnsRecursor{
mode: uint32(0666),
}
})
}

View file

@ -0,0 +1,675 @@
package powerdns_recursor
import (
"net"
"os"
"runtime"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf/testutil"
)
var metrics = "all-outqueries\t3591637\nanswers-slow\t36451\nanswers0-1\t177297\nanswers1-10\t1209328\n" +
"answers10-100\t1238786\nanswers100-1000\t402917\nauth-zone-queries\t4\nauth4-answers-slow\t44248\n" +
"auth4-answers0-1\t59169\nauth4-answers1-10\t1747403\nauth4-answers10-100\t1315621\n" +
"auth4-answers100-1000\t424683\nauth6-answers-slow\t0\nauth6-answers0-1\t0\nauth6-answers1-10\t0\n" +
"auth6-answers10-100\t0\nauth6-answers100-1000\t0\ncache-entries\t295917\ncache-hits\t148630\n" +
"cache-misses\t2916149\ncase-mismatches\t0\nchain-resends\t418602\nclient-parse-errors\t0\n" +
"concurrent-queries\t0\ndlg-only-drops\t0\ndnssec-queries\t151536\ndnssec-result-bogus\t0\n" +
"dnssec-result-indeterminate\t0\ndnssec-result-insecure\t0\ndnssec-result-nta\t0\n" +
"dnssec-result-secure\t46\ndnssec-validations\t46\ndont-outqueries\t62\necs-queries\t0\n" +
"ecs-responses\t0\nedns-ping-matches\t0\nedns-ping-mismatches\t0\nfailed-host-entries\t33\n" +
"fd-usage\t32\nignored-packets\t0\nipv6-outqueries\t0\nipv6-questions\t0\nmalloc-bytes\t0\n" +
"max-cache-entries\t1000000\nmax-mthread-stack\t33747\nmax-packetcache-entries\t500000\n" +
"negcache-entries\t100070\nno-packet-error\t0\nnoedns-outqueries\t72409\nnoerror-answers\t25155259\n" +
"noping-outqueries\t0\nnsset-invalidations\t2385\nnsspeeds-entries\t3571\nnxdomain-answers\t3307768\n" +
"outgoing-timeouts\t43876\noutgoing4-timeouts\t43876\noutgoing6-timeouts\t0\nover-capacity-drops\t0\n" +
"packetcache-entries\t80756\npacketcache-hits\t25698497\npacketcache-misses\t3064625\npolicy-drops\t0\n" +
"policy-result-custom\t0\npolicy-result-drop\t0\npolicy-result-noaction\t3064779\npolicy-result-nodata\t0\n" +
"policy-result-nxdomain\t0\npolicy-result-truncate\t0\nqa-latency\t6587\nquery-pipe-full-drops\t0\n" +
"questions\t28763276\nreal-memory-usage\t280465408\nresource-limits\t0\nsecurity-status\t1\n" +
"server-parse-errors\t0\nservfail-answers\t300249\nspoof-prevents\t0\nsys-msec\t1296588\n" +
"tcp-client-overflow\t0\ntcp-clients\t0\ntcp-outqueries\t116\ntcp-questions\t130\nthrottle-entries\t33\n" +
"throttled-out\t13187\nthrottled-outqueries\t13187\ntoo-old-drops\t2\nudp-in-errors\t4\n" +
"udp-noport-errors\t2908\nudp-recvbuf-errors\t0\nudp-sndbuf-errors\t0\nunauthorized-tcp\t0\n" +
"unauthorized-udp\t0\nunexpected-packets\t0\nunreachables\t1695\nuptime\t165725\nuser-msec\t1266384\n" +
"x-our-latency\t19\nx-ourtime-slow\t632\nx-ourtime0-1\t3060079\nx-ourtime1-2\t3351\nx-ourtime16-32\t197\n" +
"x-ourtime2-4\t302\nx-ourtime4-8\t194\nx-ourtime8-16\t24\n"
// first metric has no "\t"
var corruptMetrics = "all-outqueries3591637\nanswers-slow\t36451\nanswers0-1\t177297\nanswers1-10\t1209328\n" +
"answers10-100\t1238786\nanswers100-1000\t402917\nauth-zone-queries\t4\nauth4-answers-slow\t44248\n" +
"auth4-answers0-1\t59169\nauth4-answers1-10\t1747403\nauth4-answers10-100\t1315621\n" +
"auth4-answers100-1000\t424683\nauth6-answers-slow\t0\nauth6-answers0-1\t0\nauth6-answers1-10\t0\n" +
"auth6-answers10-100\t0\nauth6-answers100-1000\t0\ncache-entries\t295917\ncache-hits\t148630\n" +
"cache-misses\t2916149\ncase-mismatches\t0\nchain-resends\t418602\nclient-parse-errors\t0\n" +
"concurrent-queries\t0\ndlg-only-drops\t0\ndnssec-queries\t151536\ndnssec-result-bogus\t0\n" +
"dnssec-result-indeterminate\t0\ndnssec-result-insecure\t0\ndnssec-result-nta\t0\n" +
"dnssec-result-secure\t46\ndnssec-validations\t46\ndont-outqueries\t62\necs-queries\t0\n" +
"ecs-responses\t0\nedns-ping-matches\t0\nedns-ping-mismatches\t0\nfailed-host-entries\t33\n" +
"fd-usage\t32\nignored-packets\t0\nipv6-outqueries\t0\nipv6-questions\t0\nmalloc-bytes\t0\n" +
"max-cache-entries\t1000000\nmax-mthread-stack\t33747\nmax-packetcache-entries\t500000\n" +
"negcache-entries\t100070\nno-packet-error\t0\nnoedns-outqueries\t72409\nnoerror-answers\t25155259\n" +
"noping-outqueries\t0\nnsset-invalidations\t2385\nnsspeeds-entries\t3571\nnxdomain-answers\t3307768\n" +
"outgoing-timeouts\t43876\noutgoing4-timeouts\t43876\noutgoing6-timeouts\t0\nover-capacity-drops\t0\n" +
"packetcache-entries\t80756\npacketcache-hits\t25698497\npacketcache-misses\t3064625\npolicy-drops\t0\n" +
"policy-result-custom\t0\npolicy-result-drop\t0\npolicy-result-noaction\t3064779\npolicy-result-nodata\t0\n" +
"policy-result-nxdomain\t0\npolicy-result-truncate\t0\nqa-latency\t6587\nquery-pipe-full-drops\t0\n" +
"questions\t28763276\nreal-memory-usage\t280465408\nresource-limits\t0\nsecurity-status\t1\n" +
"server-parse-errors\t0\nservfail-answers\t300249\nspoof-prevents\t0\nsys-msec\t1296588\n" +
"tcp-client-overflow\t0\ntcp-clients\t0\ntcp-outqueries\t116\ntcp-questions\t130\nthrottle-entries\t33\n" +
"throttled-out\t13187\nthrottled-outqueries\t13187\ntoo-old-drops\t2\nudp-in-errors\t4\n" +
"udp-noport-errors\t2908\nudp-recvbuf-errors\t0\nudp-sndbuf-errors\t0\nunauthorized-tcp\t0\n" +
"unauthorized-udp\t0\nunexpected-packets\t0\nunreachables\t1695\nuptime\t165725\nuser-msec\t1266384\n" +
"x-our-latency\t19\nx-ourtime-slow\t632\nx-ourtime0-1\t3060079\nx-ourtime1-2\t3351\nx-ourtime16-32\t197\n" +
"x-ourtime2-4\t302\nx-ourtime4-8\t194\nx-ourtime8-16\t24\n"
// integer overflow
var intOverflowMetrics = "all-outqueries\t18446744073709550195\nanswers-slow\t36451\nanswers0-1\t177297\nanswers1-10\t1209328\n" +
"answers10-100\t1238786\nanswers100-1000\t402917\nauth-zone-queries\t4\nauth4-answers-slow\t44248\n" +
"auth4-answers0-1\t59169\nauth4-answers1-10\t1747403\nauth4-answers10-100\t1315621\n" +
"auth4-answers100-1000\t424683\nauth6-answers-slow\t0\nauth6-answers0-1\t0\nauth6-answers1-10\t0\n" +
"auth6-answers10-100\t0\nauth6-answers100-1000\t0\ncache-entries\t295917\ncache-hits\t148630\n" +
"cache-misses\t2916149\ncase-mismatches\t0\nchain-resends\t418602\nclient-parse-errors\t0\n" +
"concurrent-queries\t0\ndlg-only-drops\t0\ndnssec-queries\t151536\ndnssec-result-bogus\t0\n" +
"dnssec-result-indeterminate\t0\ndnssec-result-insecure\t0\ndnssec-result-nta\t0\n" +
"dnssec-result-secure\t46\ndnssec-validations\t46\ndont-outqueries\t62\necs-queries\t0\n" +
"ecs-responses\t0\nedns-ping-matches\t0\nedns-ping-mismatches\t0\nfailed-host-entries\t33\n" +
"fd-usage\t32\nignored-packets\t0\nipv6-outqueries\t0\nipv6-questions\t0\nmalloc-bytes\t0\n" +
"max-cache-entries\t1000000\nmax-mthread-stack\t33747\nmax-packetcache-entries\t500000\n" +
"negcache-entries\t100070\nno-packet-error\t0\nnoedns-outqueries\t72409\nnoerror-answers\t25155259\n" +
"noping-outqueries\t0\nnsset-invalidations\t2385\nnsspeeds-entries\t3571\nnxdomain-answers\t3307768\n" +
"outgoing-timeouts\t43876\noutgoing4-timeouts\t43876\noutgoing6-timeouts\t0\nover-capacity-drops\t0\n" +
"packetcache-entries\t80756\npacketcache-hits\t25698497\npacketcache-misses\t3064625\npolicy-drops\t0\n" +
"policy-result-custom\t0\npolicy-result-drop\t0\npolicy-result-noaction\t3064779\npolicy-result-nodata\t0\n" +
"policy-result-nxdomain\t0\npolicy-result-truncate\t0\nqa-latency\t6587\nquery-pipe-full-drops\t0\n" +
"questions\t28763276\nreal-memory-usage\t280465408\nresource-limits\t0\nsecurity-status\t1\n" +
"server-parse-errors\t0\nservfail-answers\t300249\nspoof-prevents\t0\nsys-msec\t1296588\n" +
"tcp-client-overflow\t0\ntcp-clients\t0\ntcp-outqueries\t116\ntcp-questions\t130\nthrottle-entries\t33\n" +
"throttled-out\t13187\nthrottled-outqueries\t13187\ntoo-old-drops\t2\nudp-in-errors\t4\n" +
"udp-noport-errors\t2908\nudp-recvbuf-errors\t0\nudp-sndbuf-errors\t0\nunauthorized-tcp\t0\n" +
"unauthorized-udp\t0\nunexpected-packets\t0\nunreachables\t1695\nuptime\t165725\nuser-msec\t1266384\n" +
"x-our-latency\t19\nx-ourtime-slow\t632\nx-ourtime0-1\t3060079\nx-ourtime1-2\t3351\nx-ourtime16-32\t197\n" +
"x-ourtime2-4\t302\nx-ourtime4-8\t194\nx-ourtime8-16\t24\n"
func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skip("Skipping on windows and darwin, as unixgram sockets are not supported")
}
// We create a fake server to return test data
controlSocket := "/tmp/pdns5724354148158589552.controlsocket"
defer os.Remove(controlSocket)
addr, err := net.ResolveUnixAddr("unixgram", controlSocket)
require.NoError(t, err, "Cannot parse unix socket")
socket, err := net.ListenUnixgram("unixgram", addr)
require.NoError(t, err, "Cannot initialize server on port")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer func() {
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()
for {
buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf)
if err != nil {
socket.Close()
return
}
data := buf[:n]
if string(data) == "get-all\n" {
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
socket.Close()
}
time.Sleep(100 * time.Millisecond)
}
}()
p := &PowerdnsRecursor{
UnixSockets: []string{controlSocket},
SocketDir: "/tmp",
SocketMode: "0666",
}
require.NoError(t, p.Init())
var acc testutil.Accumulator
require.NoError(t, acc.GatherError(p.Gather))
wg.Wait()
testReturnedMetrics(t, &acc)
}
func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skip("Skipping on windows and darwin, as unixgram sockets are not supported")
}
// We create a fake server to return test data
controlSocket := "/tmp/pdns-v2-5724354148158589552.controlsocket"
defer os.Remove(controlSocket)
addr, err := net.ResolveUnixAddr("unixgram", controlSocket)
require.NoError(t, err, "Cannot parse unix socket")
socket, err := net.ListenUnixgram("unixgram", addr)
require.NoError(t, err, "Cannot initialize server on port")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer func() {
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()
for {
status := make([]byte, 4)
n, _, err := socket.ReadFromUnix(status)
if err != nil || n != 4 {
socket.Close()
return
}
buf := make([]byte, 1024)
n, remote, err := socket.ReadFromUnix(buf)
if err != nil {
socket.Close()
return
}
data := buf[:n]
if string(data) == "get-all" {
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
socket.Close()
}
time.Sleep(100 * time.Millisecond)
}
}()
p := &PowerdnsRecursor{
UnixSockets: []string{controlSocket},
SocketDir: "/tmp",
SocketMode: "0666",
ControlProtocolVersion: 2,
}
require.NoError(t, p.Init())
var acc testutil.Accumulator
require.NoError(t, acc.GatherError(p.Gather))
wg.Wait()
testReturnedMetrics(t, &acc)
}
func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skip("Skipping on windows and darwin, as unixgram sockets are not supported")
}
// We create a fake server to return test data
controlSocket := "/tmp/pdns-v3-5724354148158589552.controlsocket"
defer os.Remove(controlSocket)
socket, err := net.Listen("unix", controlSocket)
require.NoError(t, err, "Cannot initialize server on port")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer func() {
socket.Close()
os.Remove(controlSocket)
wg.Done()
}()
for {
conn, err := socket.Accept()
if err != nil {
return
}
status := make([]byte, 4)
n, err := conn.Read(status)
if err != nil || n != 4 {
return
}
dataLen, err := readNativeUIntFromConn(conn)
if err != nil || dataLen == 0 || dataLen >= 16384 {
return
}
buf := make([]byte, dataLen)
n, err = conn.Read(buf)
if err != nil || uint(n) != dataLen {
return
}
if string(buf) == "get-all" {
conn.Write([]byte{0, 0, 0, 0}) //nolint:errcheck // ignore the returned error as we need to close the socket anyway
metrics := []byte(metrics)
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
conn.Write(metrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
socket.Close()
}
time.Sleep(100 * time.Millisecond)
}
}()
p := &PowerdnsRecursor{
UnixSockets: []string{controlSocket},
SocketDir: "/tmp",
SocketMode: "0666",
ControlProtocolVersion: 3,
}
require.NoError(t, p.Init())
var acc testutil.Accumulator
require.NoError(t, acc.GatherError(p.Gather))
wg.Wait()
testReturnedMetrics(t, &acc)
}
func testReturnedMetrics(t *testing.T, acc *testutil.Accumulator) {
intMetrics := []string{"all-outqueries", "answers-slow", "answers0-1", "answers1-10",
"answers10-100", "answers100-1000", "auth-zone-queries", "auth4-answers-slow",
"auth4-answers0-1", "auth4-answers1-10", "auth4-answers10-100", "auth4-answers100-1000",
"auth6-answers-slow", "auth6-answers0-1", "auth6-answers1-10", "auth6-answers10-100",
"auth6-answers100-1000", "cache-entries", "cache-hits", "cache-misses", "case-mismatches",
"chain-resends", "client-parse-errors", "concurrent-queries", "dlg-only-drops", "dnssec-queries",
"dnssec-result-bogus", "dnssec-result-indeterminate", "dnssec-result-insecure", "dnssec-result-nta",
"dnssec-result-secure", "dnssec-validations", "dont-outqueries", "ecs-queries", "ecs-responses",
"edns-ping-matches", "edns-ping-mismatches", "failed-host-entries", "fd-usage", "ignored-packets",
"ipv6-outqueries", "ipv6-questions", "malloc-bytes", "max-cache-entries", "max-mthread-stack",
"max-packetcache-entries", "negcache-entries", "no-packet-error", "noedns-outqueries",
"noerror-answers", "noping-outqueries", "nsset-invalidations", "nsspeeds-entries",
"nxdomain-answers", "outgoing-timeouts", "outgoing4-timeouts", "outgoing6-timeouts",
"over-capacity-drops", "packetcache-entries", "packetcache-hits", "packetcache-misses",
"policy-drops", "policy-result-custom", "policy-result-drop", "policy-result-noaction",
"policy-result-nodata", "policy-result-nxdomain", "policy-result-truncate", "qa-latency",
"query-pipe-full-drops", "questions", "real-memory-usage", "resource-limits", "security-status",
"server-parse-errors", "servfail-answers", "spoof-prevents", "sys-msec", "tcp-client-overflow",
"tcp-clients", "tcp-outqueries", "tcp-questions", "throttle-entries", "throttled-out", "throttled-outqueries",
"too-old-drops", "udp-in-errors", "udp-noport-errors", "udp-recvbuf-errors", "udp-sndbuf-errors",
"unauthorized-tcp", "unauthorized-udp", "unexpected-packets", "unreachables", "uptime", "user-msec",
"x-our-latency", "x-ourtime-slow", "x-ourtime0-1", "x-ourtime1-2", "x-ourtime16-32",
"x-ourtime2-4", "x-ourtime4-8", "x-ourtime8-16"}
for _, metric := range intMetrics {
require.True(t, acc.HasInt64Field("powerdns_recursor", metric), metric)
}
}
func TestPowerdnsRecursorParseMetrics(t *testing.T) {
values := parseResponse(metrics)
tests := []struct {
key string
value int64
}{
{"all-outqueries", 3591637},
{"answers-slow", 36451},
{"answers0-1", 177297},
{"answers1-10", 1209328},
{"answers10-100", 1238786},
{"answers100-1000", 402917},
{"auth-zone-queries", 4},
{"auth4-answers-slow", 44248},
{"auth4-answers0-1", 59169},
{"auth4-answers1-10", 1747403},
{"auth4-answers10-100", 1315621},
{"auth4-answers100-1000", 424683},
{"auth6-answers-slow", 0},
{"auth6-answers0-1", 0},
{"auth6-answers1-10", 0},
{"auth6-answers10-100", 0},
{"auth6-answers100-1000", 0},
{"cache-entries", 295917},
{"cache-hits", 148630},
{"cache-misses", 2916149},
{"case-mismatches", 0},
{"chain-resends", 418602},
{"client-parse-errors", 0},
{"concurrent-queries", 0},
{"dlg-only-drops", 0},
{"dnssec-queries", 151536},
{"dnssec-result-bogus", 0},
{"dnssec-result-indeterminate", 0},
{"dnssec-result-insecure", 0},
{"dnssec-result-nta", 0},
{"dnssec-result-secure", 46},
{"dnssec-validations", 46},
{"dont-outqueries", 62},
{"ecs-queries", 0},
{"ecs-responses", 0},
{"edns-ping-matches", 0},
{"edns-ping-mismatches", 0},
{"failed-host-entries", 33},
{"fd-usage", 32},
{"ignored-packets", 0},
{"ipv6-outqueries", 0},
{"ipv6-questions", 0},
{"malloc-bytes", 0},
{"max-cache-entries", 1000000},
{"max-mthread-stack", 33747},
{"max-packetcache-entries", 500000},
{"negcache-entries", 100070},
{"no-packet-error", 0},
{"noedns-outqueries", 72409},
{"noerror-answers", 25155259},
{"noping-outqueries", 0},
{"nsset-invalidations", 2385},
{"nsspeeds-entries", 3571},
{"nxdomain-answers", 3307768},
{"outgoing-timeouts", 43876},
{"outgoing4-timeouts", 43876},
{"outgoing6-timeouts", 0},
{"over-capacity-drops", 0},
{"packetcache-entries", 80756},
{"packetcache-hits", 25698497},
{"packetcache-misses", 3064625},
{"policy-drops", 0},
{"policy-result-custom", 0},
{"policy-result-drop", 0},
{"policy-result-noaction", 3064779},
{"policy-result-nodata", 0},
{"policy-result-nxdomain", 0},
{"policy-result-truncate", 0},
{"qa-latency", 6587},
{"query-pipe-full-drops", 0},
{"questions", 28763276},
{"real-memory-usage", 280465408},
{"resource-limits", 0},
{"security-status", 1},
{"server-parse-errors", 0},
{"servfail-answers", 300249},
{"spoof-prevents", 0},
{"sys-msec", 1296588},
{"tcp-client-overflow", 0},
{"tcp-clients", 0},
{"tcp-outqueries", 116},
{"tcp-questions", 130},
{"throttle-entries", 33},
{"throttled-out", 13187},
{"throttled-outqueries", 13187},
{"too-old-drops", 2},
{"udp-in-errors", 4},
{"udp-noport-errors", 2908},
{"udp-recvbuf-errors", 0},
{"udp-sndbuf-errors", 0},
{"unauthorized-tcp", 0},
{"unauthorized-udp", 0},
{"unexpected-packets", 0},
{"unreachables", 1695},
{"uptime", 165725},
{"user-msec", 1266384},
{"x-our-latency", 19},
{"x-ourtime-slow", 632},
{"x-ourtime0-1", 3060079},
{"x-ourtime1-2", 3351},
{"x-ourtime16-32", 197},
{"x-ourtime2-4", 302},
{"x-ourtime4-8", 194},
{"x-ourtime8-16", 24},
}
for _, test := range tests {
value, ok := values[test.key]
require.Truef(t, ok, "Did not find key for metric %s in values", test.key)
require.EqualValuesf(t, value, test.value, "Metric: %s, Expected: %d, actual: %d", test.key, test.value, value)
}
}
func TestPowerdnsRecursorParseCorruptMetrics(t *testing.T) {
values := parseResponse(corruptMetrics)
tests := []struct {
key string
value int64
}{
{"answers-slow", 36451},
{"answers0-1", 177297},
{"answers1-10", 1209328},
{"answers10-100", 1238786},
{"answers100-1000", 402917},
{"auth-zone-queries", 4},
{"auth4-answers-slow", 44248},
{"auth4-answers0-1", 59169},
{"auth4-answers1-10", 1747403},
{"auth4-answers10-100", 1315621},
{"auth4-answers100-1000", 424683},
{"auth6-answers-slow", 0},
{"auth6-answers0-1", 0},
{"auth6-answers1-10", 0},
{"auth6-answers10-100", 0},
{"auth6-answers100-1000", 0},
{"cache-entries", 295917},
{"cache-hits", 148630},
{"cache-misses", 2916149},
{"case-mismatches", 0},
{"chain-resends", 418602},
{"client-parse-errors", 0},
{"concurrent-queries", 0},
{"dlg-only-drops", 0},
{"dnssec-queries", 151536},
{"dnssec-result-bogus", 0},
{"dnssec-result-indeterminate", 0},
{"dnssec-result-insecure", 0},
{"dnssec-result-nta", 0},
{"dnssec-result-secure", 46},
{"dnssec-validations", 46},
{"dont-outqueries", 62},
{"ecs-queries", 0},
{"ecs-responses", 0},
{"edns-ping-matches", 0},
{"edns-ping-mismatches", 0},
{"failed-host-entries", 33},
{"fd-usage", 32},
{"ignored-packets", 0},
{"ipv6-outqueries", 0},
{"ipv6-questions", 0},
{"malloc-bytes", 0},
{"max-cache-entries", 1000000},
{"max-mthread-stack", 33747},
{"max-packetcache-entries", 500000},
{"negcache-entries", 100070},
{"no-packet-error", 0},
{"noedns-outqueries", 72409},
{"noerror-answers", 25155259},
{"noping-outqueries", 0},
{"nsset-invalidations", 2385},
{"nsspeeds-entries", 3571},
{"nxdomain-answers", 3307768},
{"outgoing-timeouts", 43876},
{"outgoing4-timeouts", 43876},
{"outgoing6-timeouts", 0},
{"over-capacity-drops", 0},
{"packetcache-entries", 80756},
{"packetcache-hits", 25698497},
{"packetcache-misses", 3064625},
{"policy-drops", 0},
{"policy-result-custom", 0},
{"policy-result-drop", 0},
{"policy-result-noaction", 3064779},
{"policy-result-nodata", 0},
{"policy-result-nxdomain", 0},
{"policy-result-truncate", 0},
{"qa-latency", 6587},
{"query-pipe-full-drops", 0},
{"questions", 28763276},
{"real-memory-usage", 280465408},
{"resource-limits", 0},
{"security-status", 1},
{"server-parse-errors", 0},
{"servfail-answers", 300249},
{"spoof-prevents", 0},
{"sys-msec", 1296588},
{"tcp-client-overflow", 0},
{"tcp-clients", 0},
{"tcp-outqueries", 116},
{"tcp-questions", 130},
{"throttle-entries", 33},
{"throttled-out", 13187},
{"throttled-outqueries", 13187},
{"too-old-drops", 2},
{"udp-in-errors", 4},
{"udp-noport-errors", 2908},
{"udp-recvbuf-errors", 0},
{"udp-sndbuf-errors", 0},
{"unauthorized-tcp", 0},
{"unauthorized-udp", 0},
{"unexpected-packets", 0},
{"unreachables", 1695},
{"uptime", 165725},
{"user-msec", 1266384},
{"x-our-latency", 19},
{"x-ourtime-slow", 632},
{"x-ourtime0-1", 3060079},
{"x-ourtime1-2", 3351},
{"x-ourtime16-32", 197},
{"x-ourtime2-4", 302},
{"x-ourtime4-8", 194},
{"x-ourtime8-16", 24},
}
for _, test := range tests {
value, ok := values[test.key]
require.Truef(t, ok, "Did not find key for metric %s in values", test.key)
require.EqualValuesf(t, value, test.value, "Metric: %s, Expected: %d, actual: %d", test.key, test.value, value)
}
}
func TestPowerdnsRecursorParseIntOverflowMetrics(t *testing.T) {
values := parseResponse(intOverflowMetrics)
tests := []struct {
key string
value int64
}{
{"answers-slow", 36451},
{"answers0-1", 177297},
{"answers1-10", 1209328},
{"answers10-100", 1238786},
{"answers100-1000", 402917},
{"auth-zone-queries", 4},
{"auth4-answers-slow", 44248},
{"auth4-answers0-1", 59169},
{"auth4-answers1-10", 1747403},
{"auth4-answers10-100", 1315621},
{"auth4-answers100-1000", 424683},
{"auth6-answers-slow", 0},
{"auth6-answers0-1", 0},
{"auth6-answers1-10", 0},
{"auth6-answers10-100", 0},
{"auth6-answers100-1000", 0},
{"cache-entries", 295917},
{"cache-hits", 148630},
{"cache-misses", 2916149},
{"case-mismatches", 0},
{"chain-resends", 418602},
{"client-parse-errors", 0},
{"concurrent-queries", 0},
{"dlg-only-drops", 0},
{"dnssec-queries", 151536},
{"dnssec-result-bogus", 0},
{"dnssec-result-indeterminate", 0},
{"dnssec-result-insecure", 0},
{"dnssec-result-nta", 0},
{"dnssec-result-secure", 46},
{"dnssec-validations", 46},
{"dont-outqueries", 62},
{"ecs-queries", 0},
{"ecs-responses", 0},
{"edns-ping-matches", 0},
{"edns-ping-mismatches", 0},
{"failed-host-entries", 33},
{"fd-usage", 32},
{"ignored-packets", 0},
{"ipv6-outqueries", 0},
{"ipv6-questions", 0},
{"malloc-bytes", 0},
{"max-cache-entries", 1000000},
{"max-mthread-stack", 33747},
{"max-packetcache-entries", 500000},
{"negcache-entries", 100070},
{"no-packet-error", 0},
{"noedns-outqueries", 72409},
{"noerror-answers", 25155259},
{"noping-outqueries", 0},
{"nsset-invalidations", 2385},
{"nsspeeds-entries", 3571},
{"nxdomain-answers", 3307768},
{"outgoing-timeouts", 43876},
{"outgoing4-timeouts", 43876},
{"outgoing6-timeouts", 0},
{"over-capacity-drops", 0},
{"packetcache-entries", 80756},
{"packetcache-hits", 25698497},
{"packetcache-misses", 3064625},
{"policy-drops", 0},
{"policy-result-custom", 0},
{"policy-result-drop", 0},
{"policy-result-noaction", 3064779},
{"policy-result-nodata", 0},
{"policy-result-nxdomain", 0},
{"policy-result-truncate", 0},
{"qa-latency", 6587},
{"query-pipe-full-drops", 0},
{"questions", 28763276},
{"real-memory-usage", 280465408},
{"resource-limits", 0},
{"security-status", 1},
{"server-parse-errors", 0},
{"servfail-answers", 300249},
{"spoof-prevents", 0},
{"sys-msec", 1296588},
{"tcp-client-overflow", 0},
{"tcp-clients", 0},
{"tcp-outqueries", 116},
{"tcp-questions", 130},
{"throttle-entries", 33},
{"throttled-out", 13187},
{"throttled-outqueries", 13187},
{"too-old-drops", 2},
{"udp-in-errors", 4},
{"udp-noport-errors", 2908},
{"udp-recvbuf-errors", 0},
{"udp-sndbuf-errors", 0},
{"unauthorized-tcp", 0},
{"unauthorized-udp", 0},
{"unexpected-packets", 0},
{"unreachables", 1695},
{"uptime", 165725},
{"user-msec", 1266384},
{"x-our-latency", 19},
{"x-ourtime-slow", 632},
{"x-ourtime0-1", 3060079},
{"x-ourtime1-2", 3351},
{"x-ourtime16-32", 197},
{"x-ourtime2-4", 302},
{"x-ourtime4-8", 194},
{"x-ourtime8-16", 24},
}
for _, test := range tests {
value, ok := values[test.key]
require.Truef(t, ok, "Did not find key for metric %s in values", test.key)
require.EqualValuesf(t, value, test.value, "Metric: %s, Expected: %d, actual: %d", test.key, test.value, value)
}
}

View file

@ -0,0 +1,89 @@
package powerdns_recursor
import (
"errors"
"fmt"
"net"
"strconv"
"strings"
"github.com/influxdata/telegraf/internal"
)
func parseResponse(metrics string) map[string]interface{} {
values := make(map[string]interface{})
s := strings.Split(metrics, "\n")
if len(s) < 1 {
return values
}
for _, metric := range s[:len(s)-1] {
m := strings.Split(metric, "\t")
if len(m) < 2 {
continue
}
i, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
continue
}
values[m[0]] = i
}
return values
}
// This below is generally unsafe but necessary in this case
// since the powerdns protocol encoding is host dependent.
// The C implementation uses size_t as the size type for the
// command length. The size and endianness of size_t change
// depending on the platform the program is being run on.
// Using the target architecture endianness and the known
// integer size, we can "recreate" the corresponding C
// behavior in an effort to maintain compatibility. Of course
// in cases where one program is compiled for i386 and the
// other for amd64 (and similar), this method will fail.
const uintSizeInBytes = strconv.IntSize / 8
func writeNativeUIntToConn(conn net.Conn, value uint) error {
intData := make([]byte, uintSizeInBytes)
switch uintSizeInBytes {
case 4:
internal.HostEndianness.PutUint32(intData, uint32(value))
case 8:
internal.HostEndianness.PutUint64(intData, uint64(value))
default:
return errors.New("unsupported system configuration")
}
_, err := conn.Write(intData)
return err
}
func readNativeUIntFromConn(conn net.Conn) (uint, error) {
intData := make([]byte, uintSizeInBytes)
n, err := conn.Read(intData)
if err != nil {
return 0, err
}
if n != uintSizeInBytes {
return 0, fmt.Errorf("did not read enough data for native uint: read '%v' bytes, expected '%v'", n, uintSizeInBytes)
}
switch uintSizeInBytes {
case 4:
return uint(internal.HostEndianness.Uint32(intData)), nil
case 8:
return uint(internal.HostEndianness.Uint64(intData)), nil
default:
return 0, errors.New("unsupported system configuration")
}
}

View file

@ -0,0 +1,81 @@
package powerdns_recursor
import (
"errors"
"net"
"os"
"path/filepath"
"time"
"github.com/google/uuid"
"github.com/influxdata/telegraf"
)
// V1 (before 4.5.0) Protocol:
// Unix datagram socket
// Synchronous request / response, individual datagrams
// Structure:
// data: byte[]
// The `data` field contains a list of commands to execute with
// the \n character after every command.
func (p *PowerdnsRecursor) gatherFromV1Server(address string, acc telegraf.Accumulator) error {
recvSocket := filepath.Join(p.SocketDir, "pdns_recursor_telegraf"+uuid.New().String())
laddr, err := net.ResolveUnixAddr("unixgram", recvSocket)
if err != nil {
return err
}
defer os.Remove(recvSocket)
raddr, err := net.ResolveUnixAddr("unixgram", address)
if err != nil {
return err
}
conn, err := net.DialUnix("unixgram", laddr, raddr)
if err != nil {
return err
}
defer conn.Close()
if err := os.Chmod(recvSocket, os.FileMode(p.mode)); err != nil {
return err
}
if err := conn.SetDeadline(time.Now().Add(defaultTimeout)); err != nil {
return err
}
// Then send the get-all command.
command := "get-all\n"
_, err = conn.Write([]byte(command))
if err != nil {
return err
}
// Read the response data.
buf := make([]byte, 16_384)
n, err := conn.Read(buf)
if err != nil {
return err
}
if n == 0 {
return errors.New("no data received")
}
metrics := string(buf)
// Process data
fields := parseResponse(metrics)
// Add server socket as a tag
tags := map[string]string{"server": address}
acc.AddFields("powerdns_recursor", fields, tags)
return nil
}

View file

@ -0,0 +1,95 @@
package powerdns_recursor
import (
"errors"
"net"
"os"
"path/filepath"
"time"
"github.com/google/uuid"
"github.com/influxdata/telegraf"
)
// V2 (4.5.0 - 4.5.9) Protocol:
// Unix datagram socket
// Synchronous request / response, individual datagrams
// Datagram 1 => status: uint32
// Datagram 2 => data: byte[] (max 16_384 bytes)
func (p *PowerdnsRecursor) gatherFromV2Server(address string, acc telegraf.Accumulator) error {
recvSocket := filepath.Join(p.SocketDir, "pdns_recursor_telegraf"+uuid.New().String())
laddr, err := net.ResolveUnixAddr("unixgram", recvSocket)
if err != nil {
return err
}
defer os.Remove(recvSocket)
raddr, err := net.ResolveUnixAddr("unixgram", address)
if err != nil {
return err
}
conn, err := net.DialUnix("unixgram", laddr, raddr)
if err != nil {
return err
}
defer conn.Close()
if err := os.Chmod(recvSocket, os.FileMode(p.mode)); err != nil {
return err
}
if err := conn.SetDeadline(time.Now().Add(defaultTimeout)); err != nil {
return err
}
// First send a 0 status code.
_, err = conn.Write([]byte{0, 0, 0, 0})
if err != nil {
return err
}
// Then send the get-all command.
command := "get-all"
_, err = conn.Write([]byte(command))
if err != nil {
return err
}
// Read the response status code.
status := make([]byte, 4)
n, err := conn.Read(status)
if err != nil {
return err
}
if n == 0 {
return errors.New("no status code received")
}
// Read the response data.
buf := make([]byte, 16_384)
n, err = conn.Read(buf)
if err != nil {
return err
}
if n == 0 {
return errors.New("no data received")
}
metrics := string(buf)
// Process data
fields := parseResponse(metrics)
// Add server socket as a tag
tags := map[string]string{"server": address}
acc.AddFields("powerdns_recursor", fields, tags)
return nil
}

View file

@ -0,0 +1,91 @@
package powerdns_recursor
import (
"errors"
"fmt"
"net"
"time"
"github.com/influxdata/telegraf"
)
// V3 (4.6.0+) Protocol:
// Standard unix stream socket
// Synchronous request / response
// Data structure:
// status: uint32
// dataLength: size_t
// data: byte[dataLength]
func gatherFromV3Server(address string, acc telegraf.Accumulator) error {
conn, err := net.Dial("unix", address)
if err != nil {
return err
}
defer conn.Close()
if err := conn.SetDeadline(time.Now().Add(defaultTimeout)); err != nil {
return err
}
// Write 4-byte response code.
if _, err = conn.Write([]byte{0, 0, 0, 0}); err != nil {
return err
}
command := []byte("get-all")
if err := writeNativeUIntToConn(conn, uint(len(command))); err != nil {
return err
}
if _, err = conn.Write(command); err != nil {
return err
}
// Now read the response.
status := make([]byte, 4)
n, err := conn.Read(status)
if err != nil {
return err
}
if n == 0 {
return errors.New("no status code received")
}
responseLength, err := readNativeUIntFromConn(conn)
if err != nil {
return err
}
if responseLength == 0 {
return errors.New("received data length was '0'")
}
// Don't allow more than 64kb of data to prevent DOS / issues
// with architecture mismatch. V2 protocol allowed for up to
// 16kb, so 64kb should give us a pretty good margin for anything
// that has been added since.
if responseLength > 64*1024 {
return fmt.Errorf("received data length was '%d', we only allow up to '%d'", responseLength, 64*1024)
}
data := make([]byte, responseLength)
n, err = conn.Read(data)
if err != nil {
return err
}
if uint(n) != responseLength {
return fmt.Errorf("no data received, expected '%v' bytes but got '%v'", responseLength, n)
}
// Process data
metrics := string(data)
fields := parseResponse(metrics)
// Add server socket as a tag
tags := map[string]string{"server": address}
acc.AddFields("powerdns_recursor", fields, tags)
return nil
}

View file

@ -0,0 +1,19 @@
# Read metrics from one or many PowerDNS Recursor servers
[[inputs.powerdns_recursor]]
## Path to the Recursor control socket.
unix_sockets = ["/var/run/pdns_recursor.controlsocket"]
## Directory to create receive socket. This default is likely not writable,
## please reference the full plugin documentation for a recommended setup.
# socket_dir = "/var/run/"
## Socket permissions for the receive socket.
# socket_mode = "0666"
## The version of the PowerDNS control protocol to use. You will have to
## change this based on your PowerDNS Recursor version, see below:
## Version 1: PowerDNS <4.5.0
## Version 2: PowerDNS 4.5.0 - 4.5.11
## Version 3: PowerDNS >=4.6.0
## By default this is set to 1.
# control_protocol_version = 1