Skip to content

Instantly share code, notes, and snippets.

@barryo
Last active August 31, 2025 09:58
Show Gist options
  • Select an option

  • Save barryo/78d9f835bdf5c8180d66cb37a07808e5 to your computer and use it in GitHub Desktop.

Select an option

Save barryo/78d9f835bdf5c8180d66cb37a07808e5 to your computer and use it in GitHub Desktop.
Authoritative PowerDNS Monitoring Plugins for Munin
#!/bin/bash
#
# Script to monitor PowerDNS performance
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#%# family=auto
#%# capabilities=autoconf
pdns_control="/usr/bin/pdns_control"
command="$pdns_control list"
if [ "$1" = "autoconf" ]; then
if [ -e "$pdns_control" ]; then
echo yes
exit 0
else
echo "no (missing $pdns_control)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power DNS errors'
echo 'graph_args -l 0 --base 1000'
echo 'graph_vlabel numbers of'
echo 'graph_category dns'
echo 'graph_info This graph shows Power DNS performance on the machine.'
echo 'corrupt_packets.label corrupt packets'
echo 'corrupt_packets.type DERIVE'
echo 'corrupt_packets.min 0'
echo 'corrupt_packets.info Number of corrupt packets received'
echo 'servfail_packets.label servfail packets'
echo 'servfail_packets.type DERIVE'
echo 'servfail_packets.min 0'
echo 'servfail_packets.info Number of times a server-failed packet was sent out'
echo 'timedout_packets.label timedout packets'
echo 'timedout_packets.type DERIVE'
echo 'timedout_packets.min 0'
echo 'timedout_packets.info Number of packets which weren not answered within timeout set'
exit 0
fi
$command | sed 's/=\([0-9]\+\),/.value \1\n/g' | egrep "corrupt|servfail|timedout" | sed 's/-/_/g'
#!/bin/bash
#
# Script to monitor PowerDNS performance
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#%# family=auto
#%# capabilities=autoconf
pdns_control="/usr/bin/pdns_control"
command="$pdns_control list"
if [ "$1" = "autoconf" ]; then
if [ -e "$pdns_control" ]; then
echo yes
exit 0
else
echo "no (missing $pdns_control)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power DNS latency'
echo 'graph_args -l 0 --base 1000'
echo 'graph_vlabel numbers of'
echo 'graph_category dns'
echo 'graph_info This graph shows Power DNS latency on the machine.'
echo 'backend_latency.label backend latency'
echo 'backend_latency.type DERIVE'
echo 'backend_latency.min 0'
echo 'backend_latency.info Backend latency'
echo 'cache_latency.label cache latency'
echo 'cache_latency.type DERIVE'
echo 'cache_latency.min 0'
echo 'cache_latency.info Cache latency'
echo 'latency.label latency'
echo 'latency.type DERIVE'
echo 'latency.min 0'
echo 'latency.info Average number of microseconds a packet spends within PowerDNS'
echo 'receive_latency.label receivelatency'
echo 'receive_latency.type DERIVE'
echo 'receive_latency.min 0'
echo 'receive_latency.info Average number of microseconds needed to receive a query'
echo 'send_latency.label latency'
echo 'send_latency.type DERIVE'
echo 'send_latency.min 0'
echo 'send_latency.info Average number of microseconds needed to send the answer'
exit 0
fi
$command | sed 's/=\([0-9]\+\),/.value \1\n/g' | egrep "latency" | sed 's/-/_/g'
#!/bin/bash
#
# Script to monitor PowerDNS performance
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#%# family=auto
#%# capabilities=autoconf
pdns_control="/usr/bin/pdns_control"
command="$pdns_control show"
if [ "$1" = "autoconf" ]; then
if [ -e "$pdns_control" ]; then
echo yes
exit 0
else
echo "no (missing $pdns_control)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power DNS database queue'
echo 'graph_args -l 0'
echo 'graph_vlabel number of waiting queries'
echo 'graph_category dns'
echo 'graph_info This graph shows Power DNS database performance on the machine.'
echo 'qsize.label qsize'
echo 'qsize.info Number of questions waiting for database attention'
echo 'qsize.type GAUGE'
exit 0
fi
echo "qsize.value $($command qsize-q)"
#!/bin/bash
#
# Script to monitor PowerDNS performance
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#%# family=auto
#%# capabilities=autoconf
pdns_control="/usr/bin/pdns_control"
command="/usr/bin/pdns_control list"
if [ "$1" = "autoconf" ]; then
if [ -e "$pdns_control" ]; then
echo yes
exit 0
else
echo "no (missing $pdns_control)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power DNS queries'
echo 'graph_args -l 0 --base 1000'
echo 'graph_vlabel numbers of'
echo 'graph_category dns'
echo 'graph_info This graph shows Power DNS performance on the machine.'
echo 'recursing_answers.label recursing answers'
echo 'recursing_answers.type DERIVE'
echo 'recursing_answers.min 0'
echo 'recursing_answers.info Number of recursive answers sent out'
echo 'recursing_questions.label recursing queries'
echo 'recursing_questions.type DERIVE'
echo 'recursing_questions.min 0'
echo 'recursing_questions.info Number of queries sent to recursor'
echo 'tcp_answers.label tcp answers'
echo 'tcp_answers.type DERIVE'
echo 'tcp_answers.min 0'
echo 'tcp_answers.info Number of answers sent out over TCP'
echo 'tcp_queries.label tcp queries'
echo 'tcp_queries.type DERIVE'
echo 'tcp_queries.min 0'
echo 'tcp_queries.info Number of TCP queries received'
echo 'udp_answers.label udp answers'
echo 'udp_answers.type DERIVE'
echo 'udp_answers.min 0'
echo 'udp_answers.info Number of answers sent out over UDP'
echo 'udp_queries.label udp queries'
echo 'udp_queries.type DERIVE'
echo 'udp_queries.min 0'
echo 'udp_queries.info Number of UDP queries received'
exit 0
fi
$command | sed 's/=\([0-9]\+\),/.value \1\n/g' | egrep "udp-|recursing|tcp" | sed 's/-/_/g'
#!/bin/bash
#
# Script to monitor PowerDNS performance
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#%# family=auto
#%# capabilities=autoconf
pdns_control="/usr/bin/pdns_control"
command="$pdns_control show"
state_file=$MUNIN_PLUGSTATE/pdns_rel.state
if [ "$1" = "autoconf" ]; then
if [ -e "$pdns_control" ]; then
echo yes
exit 0
else
echo "no (missing $pdns_control)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Power DNS Packet Cache Performance'
echo 'graph_args -l 0 --upper-limit 100 --base 1000'
echo 'graph_vlabel %'
echo 'graph_category dns'
echo 'graph_info This graph shows the Power DNS packet cache performance on the machine.'
echo 'packetcache_hitrate.label packet cache hitrate'
echo 'packetcache_hitrate.type GAUGE'
echo 'packetcache_hitrate.min 0'
echo 'packetcache_hitrate.max 100'
echo 'packetcache_hitrate.info Hits on the packets cache'
exit 0
fi
hits=$($command packetcache-hit)
queries=$($command udp-queries)
if [ -f "$state_file" ]; then
old_hits=$(head -n1 "$state_file")
old_queries=$(tail -n1 "$state_file")
fi
if [ -f "$state_file" ] && [ "$(stat --format=%Y "$state_file")" -gt "$(date --date="7 minutes ago" +%s)" ] ; then
d_hits=$((hits - old_hits))
d_queries=$((queries - old_queries))
if [ $d_queries -gt 0 ] ; then
echo packetcache_hitrate.value $(( d_hits * 100 / d_queries ))
fi
fi
echo "$hits" > "$state_file"
echo "$queries" >> "$state_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment