update
changeset 0 55d66efee4e0
equal deleted inserted replaced
-1:000000000000 0:55d66efee4e0
       
     1 #!/bin/bash
       
     2 #
       
     3 # Added --fork compatibility to support multiple control sockets
       
     4 #
       
     5 # Original by ahu @ pdns-dev team
       
     6 # Modified by Daniel Selans <dan.s at hostdime.com>
       
     7 # 09.02.07
       
     8 #
       
     9 
       
    10 SOCKETDIR=/var/run # Leave off the trailing slash
       
    11 CHKFORK=`ps -C pdns_recursor --no-headers | wc -l`
       
    12 
       
    13 # Quick sanity check
       
    14 if [ CHKFORK = 0 ]
       
    15 then
       
    16          echo "pdns_recursor is not running!"
       
    17          exit
       
    18 fi
       
    19 
       
    20 TSTAMP=$(date +%s)
       
    21 
       
    22 VARIABLES="questions tcp-questions cache-entries concurrent-queries\
       
    23             nxdomain-answers noerror-answers\
       
    24             servfail-answers tcp-outqueries\
       
    25             outgoing-timeouts nsspeeds-entries negcache-entries all-outqueries throttled-out\
       
    26             cache-hits cache-misses answers0-1 answers1-10  answers10-100 answers100-1000 answers-slow\
       
    27             qa-latency throttle-entries sys-msec user-msec  unauthorized-udp unauthorized-tcp client-parse-errors\
       
    28             server-parse-errors"
       
    29 
       
    30 UVARIABLES=$(echo $VARIABLES | tr '[a-z]' '[A-Z]' | tr - _ )
       
    31 
       
    32 
       
    33 
       
    34 if [ $CHKFORK = 2 ]
       
    35 then
       
    36          # Running with --fork
       
    37          SOCKETS=`ls -t -1 $SOCKETDIR/pdns_recursor.controlsocket.* | head --lines 2`
       
    38          FORK="yes"
       
    39          COUNT=0
       
    40 
       
    41          for i in $SOCKETS
       
    42          do
       
    43                  PID=`echo $i | cut -d . -f3`
       
    44                  rec_control --socket-dir=$SOCKETDIR --socket-pid=$PID GET $VARIABLES |
       
    45                  (
       
    46                  for a in $UVARIABLES
       
    47                  do
       
    48                          read $a
       
    49                  done
       
    50                  rrdtool update pdns_recursor.$COUNT.rrd \
       
    51                          -t \
       
    52                          $(for a in $VARIABLES
       
    53                          do
       
    54                                  echo -n $a:
       
    55                          done | sed 's/:$//' ) \
       
    56                  $TSTAMP$(
       
    57                          for a in $UVARIABLES
       
    58                          do
       
    59                                  echo -n :${!a}
       
    60                          done)
       
    61                  )
       
    62                  COUNT=$(($COUNT + 1))
       
    63          done
       
    64 
       
    65 else
       
    66          rec_control --socket-dir=$SOCKETDIR  GET $VARIABLES |
       
    67          (
       
    68          for a in $UVARIABLES
       
    69          do
       
    70                  read $a
       
    71          done
       
    72          rrdtool update pdns_recursor.rrd \
       
    73                  -t \
       
    74                  $(for a in $VARIABLES
       
    75                  do
       
    76                          echo -n $a:
       
    77                  done | sed 's/:$//' ) \
       
    78          $TSTAMP$(
       
    79                  for a in $UVARIABLES
       
    80                  do
       
    81                          echo -n :${!a}
       
    82                  done)
       
    83          )
       
    84 fi