Statistiche BIND99

"Davide D'Amico" <[email protected]> Sun, 12 Jan 2014 20:30:19 +0100
Newsgroups gmane.os.freebsd.italian.varie
Message-ID <CAHykR++Vkkfcs5J31deBnabUJ+UEcO7t7osJ95ogdQcR15hLeQ@mail.gmail.com>
Ciao, cercando in rete non ho trovato granché in merito al raccogliere le
statistiche di bind99 così mi sono attenuto allo stretto indispensabile,
utilizzando rndc stats.
Purtroppo le statistiche di rndc stats fanno riferimento a quando è stato
riavviato bind99: riavviare il demone per le statistiche non mi sembra
molto carino, così ho fatto una robetta molto semplice: ogni giorno alle
00.00 lancio un rndc stats, salvandomi l'output del giorno precedente e poi
(nel mio caso) mandarmi una mail con il diff dei due stats (ma si può
facilmente adattare per inserirlo in snmpd).

L'unico passo aggiuntivo che ho fatto è rendere "machine readable" l'output
di rndc stats, seguendo l'esempio presente su
http://www.packetmischief.ca/monitoring-bind9/. Io però ho usato sh/awk.




STATS_FILE=$1
awk '{
  category = "";
  view = "";
  while (getline) {
    if ( $0 ~ /^\-\-\-\ Statistics Dump/ ) {
      continue;
    }
    if ( $0 ~ /^\+\+\ (.*)\ \+\+/ ) {
      category = "";
      view = "";
      for (i = 2; i< NF; i++)
        if (category)
          category = category "_" tolower($i);
        else
          category = tolower($i);
    }
    if ( substr($0,1,6) == "[View:" ) {
      # we are on a view
      if (substr($2,length($2),1) == "]")
        view = tolower(substr($2,1,length($2)-1));
      else
        view = tolower($2);
    }
    if ( $0 ~ /^\[(.*) \(view:/ ) {
      # we are on a view
      view = tolower(substr($1,2));
    }
    if ( substr($0,1,1) != "+" && substr($0,1,1) != "[" ) {
      val = $1;
      section = "";
      for (i = 2; i<= NF; i++)
        if (section)
          section = section "_" tolower($i);
        else
          section = tolower($i);
      # we are on a leaf
      if (view)
        print category "_" view "_" section ":" val;
      else
        print category "_" section ":" val;
    }
  }
}' $STATS_FILE

exit 0


Nel mio caso, come detto sopra, confronto le stats di due giorni
consecutivi:

#!/bin/sh

B9_MACH_SH="/usr/local/vbin/bind9-stats-parse.sh"

RDATE=$(date "+%Y%m%d")
RNDC="/usr/local/sbin/rndc"
STATS_FILE="/var/named/var/stats/named.stats"
cp ${STATS_FILE} ${STATS_FILE}.yesterday
truncate -s 0 ${STATS_FILE}
${RNDC} stats
$B9_MACH_SH < ${STATS_FILE}.yesterday > ${STATS_FILE}.mach_yesterday
$B9_MACH_SH < ${STATS_FILE} > ${STATS_FILE}.mach
for i in $(cat ${STATS_FILE}.mach); do
  LBL=$(echo "${i}" | cut -d: -f 1)
  VAL=$(echo "${i}" | cut -d: -f 2)
  VAL_Y=$(grep "${LBL}:" ${STATS_FILE}.mach_yesterday | cut -d: -f 2)
  if [ "x${VAL_Y}" != "x" ]; then
    DIFF=$(expr ${VAL} - ${VAL_Y})
    echo "${LBL}: ${DIFF}"
  fi
done

rm -f ${STATS_FILE}.yesterday ${STATS_FILE}.mach_yesterday

exit 0

Enjoy,
--
d.

_______________________________________________
Varie mailing list
[email protected]
http://mailman.gufi.org/mailman/listinfo/varie