[mrtg] Monitoring DNS requests

O'Reilly, Stuart stuart at aurora-solutions.co.uk
Mon May 5 22:22:26 MEST 2003


I'm trying to monitor the amount of DNS requests my server gets but I'm
not having much luck. I have named.conf setup like so:

options {
        directory "/var/named";                 // This is the working
directory
        listen-on { 217.155.123.xxx; };         // Listens on this IP
only
        pid-file "named.pid";                   // Put the pid file in
the working dir
        allow-query { any; };                   // This is the default
        recursion yes;                          // Do not provide
recursion service
};

# Use with the following in named.conf, adjusting the allow list as
needed:
 key "rndc-key" {
       algorithm hmac-md5;
       secret "23CwcFzbNKBRh/FruRVwNg==";
 };

 controls {
       inet 217.155.123.xxx port 953
               allow { 217.155.123.xxx; } keys { "rndc-key"; };
 };


I have rndc.key and rndc.conf files aswell (generated by rndc-config).
The dns section of the mrtg.cfg file looks like this:

# Sample entry to monitor DNS requests per hour

Target[bind]: `/usr/local/apache/mrtg/cfg/dnsstats.pl`
Options[bind]: gauge,growright,nopercent,integer,unknaszero
Title[bind]: DNS Server
MaxBytes[bind]: 32000
AbsMax[bind]: 64000
WithPeak[bind]: wmy
ShortLegend[bind]:queries/m
YLegend[bind]: Qs per Minute
Legend1[bind]: Queries received over 1 minute
Legend2[bind]: Failed Queries received over 1 minute
Legend3[bind]: Maximal Queries over 5 minutes
Legend4[bind]: Maximal Failed Queries over 5 minutes
LegendI[bind]:  Queries:
LegendO[bind]:  Failures:
PageTop[bind]: <H1>DNS Info</H1>  

With dnsstats.pl looking like this:

#!/usr/bin/perl
use strict;
# Set files to use, change these to suit your needs
my $oldstatfile = "/tmp/dns-old.txt";
my $newstatfile = "/var/named/named.stats";

# Obtain old DNS stats from stored file
open(OLDF, "$oldstatfile");
my @raw_data = <OLDF>;
close(OLDF);

my $oldsuccess = @raw_data[0];
my $oldfailure = @raw_data[1];

chomp($oldsuccess);
chomp($oldfailure);


# Check if there is data, if not, initialize
if (! $oldsuccess) {
    $oldsuccess = 0;
}

if (! $oldfailure) {
    $oldfailure = 0;
}


# Get new data from file, first clean the stats file and dump new
system("cat /dev/null > $newstatfile");
system("/usr/sbin/rndc stats");
open(NEWF, "$newstatfile");
my @dns_data = <NEWF>;
close(NEWF);

my $newsuccess = 0;
my $newfailure = 0;
my $line;
my $foundsuccess = 0;
my $foundfailure = 0;


foreach $line (@dns_data) {
    if (($line =~ /^success ([0-9]*)/) && ($foundsuccess == 0)) {
        $foundsuccess = 1;
        $newsuccess = $1;
    }

    if (($line =~ /^failure ([0-9]*)/) && ($foundfailure == 0)) {
        $foundfailure = 1;
        $newfailure = $1;
    }
}


# Calculate difference between old and new. Divide by 5 to get per
minute
my $diffsuccess = ($newsuccess - $oldsuccess) / 5;
my $difffailure = ($newfailure - $oldfailure) / 5;


# Store new data
open(OLDF, ">$oldstatfile");
print(OLDF "$newsuccess\n$newfailure");
close(OLDF);

# Print difference
print("$diffsuccess \n$difffailure \n");


I do get a named.stats file created with the various figures in it, but
my graph won't display any information.  Can anyone help me?

Thanks,

Stuart

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list