#!/bin/bash
#
# Added --fork compatibility to support multiple control sockets
#
# Original by ahu @ pdns-dev team
# Modified by Daniel Selans <dan.s at hostdime.com>
# 09.02.07
#
SOCKETDIR=/var/run # Leave off the trailing slash
CHKFORK=`ps -C pdns_recursor --no-headers | wc -l`
# Quick sanity check
if [ CHKFORK = 0 ]
then
echo "pdns_recursor is not running!"
exit
fi
TSTAMP=$(date +%s)
VARIABLES="questions tcp-questions cache-entries concurrent-queries\
nxdomain-answers noerror-answers\
servfail-answers tcp-outqueries\
outgoing-timeouts nsspeeds-entries negcache-entries all-outqueries throttled-out\
cache-hits cache-misses answers0-1 answers1-10 answers10-100 answers100-1000 answers-slow\
qa-latency throttle-entries sys-msec user-msec unauthorized-udp unauthorized-tcp client-parse-errors\
server-parse-errors"
UVARIABLES=$(echo $VARIABLES | tr '[a-z]' '[A-Z]' | tr - _ )
if [ $CHKFORK = 2 ]
then
# Running with --fork
SOCKETS=`ls -t -1 $SOCKETDIR/pdns_recursor.controlsocket.* | head --lines 2`
FORK="yes"
COUNT=0
for i in $SOCKETS
do
PID=`echo $i | cut -d . -f3`
rec_control --socket-dir=$SOCKETDIR --socket-pid=$PID GET $VARIABLES |
(
for a in $UVARIABLES
do
read $a
done
rrdtool update pdns_recursor.$COUNT.rrd \
-t \
$(for a in $VARIABLES
do
echo -n $a:
done | sed 's/:$//' ) \
$TSTAMP$(
for a in $UVARIABLES
do
echo -n :${!a}
done)
)
COUNT=$(($COUNT + 1))
done
else
rec_control --socket-dir=$SOCKETDIR GET $VARIABLES |
(
for a in $UVARIABLES
do
read $a
done
rrdtool update pdns_recursor.rrd \
-t \
$(for a in $VARIABLES
do
echo -n $a:
done | sed 's/:$//' ) \
$TSTAMP$(
for a in $UVARIABLES
do
echo -n :${!a}
done)
)
fi