Bind mrtg stats

Because I couldn’t find any that worked.

(Dark blue: incoming queries, light blue: outgoing/recursive lookups)

mrtg.cfg sample:

# Bind
Title[bind]: Bind Queries
Target[bind]: `/etc/mrtg/bind-stats.sh`
PageTop[bind]: <H1> Bind queries per minute on vm1 </H1>
Options[bind]: growright,pngdate,nobanner,gauge,nopercent,noinfo
MaxBytes[bind]: 50000
Ylegend[bind]: Queries/min
ShortLegend[bind]:  queries/min
LegendO[bind]: Incoming Bind queries per minute
LegendI[bind]: Outcoing Bind queries per minute
Legend2[bind]: Incoming Bind queries per minute
Legend1[bind]: Outcoing Bind queries per minute

bind-stats.sh:

#!/bin/bash
# Bind MRTG stats
# by Yeri Tiete (Tuinslak) - 10/02/2011
# https://yeri.be
#
# mrtg.cfg sample:
################################################################################
#	#
#	# Bind
#	#
#	Title[bind]: Bind Queries
#	Target[bind]: `/etc/mrtg/bind-stats.sh`
#	PageTop[bind]: <H1> Bind queries per minute on vm1 </H1>
#	Options[bind]: growright,pngdate,nobanner,gauge,nopercent,noinfo
#	MaxBytes[bind]: 50000
#	Ylegend[bind]: Queries/min
#	ShortLegend[bind]:  queries/min
#	LegendO[bind]: Incoming Bind queries per minute
#	LegendI[bind]: Outcoing Bind queries per minute
#	Legend2[bind]: Incoming Bind queries per minute
#	Legend1[bind]: Outcoing Bind queries per minute
################################################################################

# file path of named.stats
FILE=/var/log/named.stats
TMPFILE=/tmp/__dnsstats.txt

# how often does mrtg run? for me it's every 10 mins
TIME=10

# make file empty
echo /dev/null > /var/log/named.stats

# generate file
/usr/sbin/rndc stats

# save number of queries
INNOW=`egrep "[^I]QUERY" $FILE | awk '{print $1 }'`
OUTNOW=`grep Outgoing $FILE -A 9 | sed '1,2d' | awk '{ SUM += $1} END { print SUM }'`

# check if tmp file exists and insert data in it if it doesnt
# this prevents a peak
[ ! -e $TMPFILE ] && echo $INNOW > $TMPFILE && echo $OUTNOW >> $TMPFILE

# get old data
INOLD=`cat $TMPFILE | sed -n 1p`
OUTOLD=`cat $TMPFILE | sed -n 2p`

# overwrite old
echo $INNOW > $TMPFILE
echo $OUTNOW >> $TMPFILE

# calculate (to get difference)
INDIFF=$[ $INNOW-$INOLD ]
OUTDIFF=$[ $OUTNOW-$OUTOLD ]

# as mrtg runs */10 > divide by 10 to get per minute
INPERMIN=$[ $INDIFF/$TIME ]
OUTPERMIN=$[ $OUTDIFF/$TIME ]

# print !
echo $OUTPERMIN
echo $INPERMIN
echo
echo

Or download the file riiiiiight here.

Be sure the named.stats file gives this kind of output:

# grep Outgoing /var/log/named.stats -A 9
++ Outgoing Queries ++
[View: default]
               64316 A
                   2 NS
                  22 SOA
                6945 PTR
                 892 MX
                1104 TXT
                3117 AAAA
                  22 SRV

… for the outgoing queries, and …

# grep QUERY /var/log/named.stats | awk '{print $1 }'
163143

for the incoming queries.

Don’t forget to

chmod +x bind-stats.sh

Live sample: vm1.rootspirit.com/mrtg/bind.html


Posted by

in

, ,

Comments

6 responses to “Bind mrtg stats”

  1. daincredibleholg avatar
    daincredibleholg

    Hi.

    Great script, thank you for that!

    I tried to get it running on my machines and this brings the following error output:

    — snip —
    ./bind-stats.sh: Zeile 54: 1
    2
    2
    2
    3
    4
    4
    4
    4
    5
    5-1 2 2 2 3 4 4 4 4 5 : Syntaxfehler im Ausdruck. (Fehlerverursachendes Zeichen ist \”2
    2
    2
    3
    4
    4
    4
    4
    5
    5-1 2 2 2 3 4 4 4 4 5 \”).
    ./bind-stats.sh: Zeile 58: /10 : Syntax Fehler: Operator erwartet. (Fehlerverursachendes Zeichen ist \”/10 \”).
    2

    — snap —

    Any ideas?
    The underlying system is a Ubuntu Server 12.04 64bit with the bind out of the official repo from Ubuntu…

  2. Yeri Tiete avatar

    Hey,

    Not quite sure what those error messages mean in German… But be sure that the named stats file exists, and has the right output.

    As it seems to be giving errors on these lines:
    # calculate (to get difference)
    INDIFF=$[ $INNOW-$INOLD ]
    OUTDIFF=$[ $OUTNOW-$OUTOLD ]

    # as mrtg runs */10 > divide by 10 to get per minute
    INPERMIN=$[ $INDIFF/$TIME ]
    OUTPERMIN=$[ $OUTDIFF/$TIME ]

  3. daincredibleholg avatar
    daincredibleholg

    Hi.

    Thanks for the quick reply. The format is the problem. But how do you create the stats file? As far as I interprete the manpage for rndc.conf, the format is not configurable. Your above grep statement give:

    — snip —
    ++ Outgoing Queries ++
    [View: default]
    [View: _bind]
    ++ Name Server Statistics ++
    260 IPv4 requests received
    13 IPv6 requests received
    84 requests with EDNS(0) received
    39 requests with TSIG received
    1 recursive queries rejected
    273 responses sent
    — snap —

    Thanks and greets,
    Holger

  4. Yeri Tiete avatar

    This is my part of the stats file:

    ++ Name Server Statistics ++
    29108842 IPv4 requests received
    27104645 requests with EDNS(0) received
    5 TCP requests received
    1 recursive queries rejected
    29107906 responses sent
    1103 truncated responses sent
    27103980 responses with EDNS(0) sent
    28415110 queries resulted in successful answer
    7510 queries resulted in authoritative answer
    29065057 queries resulted in non authoritative answer
    3471 queries resulted in referral answer
    175743 queries resulted in nxrrset
    35305 queries resulted in SERVFAIL
    478243 queries resulted in NXDOMAIN
    484688 queries caused recursion
    843 duplicate queries received
    93 queries dropped
    1 other query failures
    ++ Zone Maintenance Statistics ++

    You can see it live here, but due to DNS spam it has ridiculous/useless graphs: http://vm1.rootspirit.com/mrtg/bind.html

    The file is generated with: /usr/sbin/rndc stats

    And in the bind config you should add these lines:
    zone-statistics yes;
    statistics-file “/var/log/named.stats”;

    And restart bind.

    I’ve seen a bug in the bind-stats.sh file though:

    echo /dev/null > /var/log/named.stats
    should be:
    cat /dev/null > /var/log/named.stats

    If it’s any help, I’ve started using Munin instead of mrtg for logging.

Leave a Reply to Named/BIND 9.8.2 + MRTG, part 2 | Linux and kitchen, and some other stuffCancel reply