Based upon DNS graph by Nathan Campi
In his scripts for graphing DNS activity, Nathan is proposing a workaround for Bind 9.The need for a workaround arises because with Bind 8 the statistics kept by named used to include the number of queries received by the server for each type of query, it was easy to retreive the data from the statistics of named to draw the graph; whileBind 9 do not collect such data anymore, they should be collected by logging all the queries and calculating statistics.
Nathan proposes to log the queries to stderr and run named though a shell script; the script will read from stderr.
I don't like that solution because:
- named is not started in the regular fashion, that could cause incompatibilities when system is upgraded (many system upgrade cause named upgrade);
- named would fail in case the sheel script fails;
While at same time, named knows how to log the queries to a separate file and it includes builtin a mechanism to rotate the file when it reaches a certain size a Perl module like File::Tail knows how to read from a file that get rotated like syslog files or this named quey log file.
The solution I propose decribed bellow.
Log the queries to a file
Configure Bind 9 to log all the queries to a file. In the example bellow, the file is called query-log, it rotates everytime the file grows over 1 MB and named keeps up to three backup versions of the file.
|
There will be up to four files created in named default directory, query-log, query-log.0, query-log.1 and query-log.2. The file that contains the most recent queries is query-log.
Examine the log file and collect statistics
The following Perl script uses the module File::Tail to read the file event when it rotates, it computes the number of queries by type.
The script saves its own PID in the file $pidfile. Upon receiving a hang-up signal, it writes the statistics in the file $dumpfile. The $log_wait_interval is used by File::Tail to set the tick clock when the Perl script should become active and try to read new entries in the log file.
This script should loop indefinitely, it should be launch at boot time (use your prefered method to launch that script).
#!/usr/local/bin/perl |
The display-bindstats.pl script
It corresponds to the script use for Bind 8 on Nathan's page. But to collect the statistics, it only has to send an hang-up signal to the script above and read the data from the file as designed in $dumpfile.
#!/bin/sh |
This script is called by SNMP in the exact way defined on Nathan's page for Bind 8.
Integration with SMF under Solaris
The following modification has been suggested to me by Robert Jansen from Brussels University:
To have this e.g. integrated under SMF under Solaris, one can define the |