#!/usr/bin/perl # # by Nate Campi # # $Id: display-bindstats.txt,v 1.2 2003/01/16 18:34:47 nate Exp $ # # setup some variables so people can easily modify this for their use $stats_file = "/var/named/stats/named.stats"; $ndc_binary = "/usr/local/sbin/ndc"; # if you don't want ndc to use its default channel, make it like this: #$ndc_channel = "-c /usr/local/etc/ndc.d/ndc"; # otherwise, leave this null: $ndc_channel = ""; # don't touch this unless you plan to modify the RRD database, and I'm # not including instructions on how to do that ;) @query_types = qw( A PTR ANY MX NS CNAME SOA SRV AAAA ); $counter = 0; $total = 0; if ((system("$ndc_binary $ndc_channel stats > /dev/null 2>&1"))) { die "Can't dump BIND stats: $!\n" } foreach (@query_types){ $d[$counter] = get_query_stats_by_type ($_); # print "type is: $_ \n"; print "$d[$counter] "; $counter++; } # get the total foreach ( $i = 0; $i <= 8; $i++ ) { $total += $d[$i]; } #print "TOTAL $total\n"; print "$total\n"; $d[9] = $total ; if ((system("cp /dev/null $stats_file"))) { die "Can't zero out bind stats: $!\n" } sub get_query_stats_by_type () { my ($type) = $_; open(FILE, "< $stats_file") or die "Can't open stats file: $!"; @lines = ; while ($line = pop @lines) { if ( $line =~ s/^(\d+)\s+\b$type\b queries$/$1/ ) { chomp $line; # print "There have been $line $type queries\n"; return $line; } }; # if we ever get here, then we didn't find the string at all print "Unable to retrieve the stats\n"; }