3 # Copyright Jean-Samuel Reynaud <js.reynaud@free.fr>
4 # Licenced under GPL v2
6 # We use this script to produce graph with munin for dns requests
8 # Thanks for Benjamin Pineau for perl cleaning and correction in non root
11 # modified for bind 9.5 by -thh 2009-04-15
15 #%# capabilities=autoconf
20 # change those to reflect your bind configuration
22 my $stat_file = "/var/log/named/stats";
24 my $rndc = "/usr/sbin/rndc";
28 my $lst = { "success" => 1,
36 #$domain =~ s/^.*bind_([\w\d\._\-]*)$/$1/;
40 # Parse the statistic file
43 open(IN,"<$stat_file") or die "Can't open $stat_file : $!";
48 my ($count,@type) = split(/ /,$_);
49 my $type = join(' ',@type);
50 #$zone = defined($zone) ? $zone : "";
52 # if (defined $lst->{$type}) {
53 # # only keep the latest occurence for each value
54 # $lst->{$type} = $count;
58 if ($type=~/successful answer/) {
59 $lst->{'success'} = $count;
60 } elsif ($type=~/FIXME/) {
61 $lst->{'referral'} = $count;
62 } elsif ($type=~/nxrrset/) {
63 $lst->{'nxrrset'} = $count;
64 } elsif ($type=~/resulted in NXDOMAIN/i) {
65 $lst->{'nxdomain'} = $count;
66 } elsif ($type=~/recursion/) {
67 $lst->{'recursion'} = $count;
68 } elsif ($type=~/failures/) {
69 $lst->{'failure'} = $count;
74 printf "%s.value %u\n", $_, $lst->{$_} foreach (keys %$lst);
80 if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) {
81 printf "graph_title Dns requests %s\n",($domain eq "" ? "all domains":$domain);
82 printf "graph_vlabel requests/s\n";
83 printf "graph_category network\n";
84 printf "graph_info This graph display dns requests for %s\n",($domain eq "" ? "all domains":$domain);
85 printf "success.label Success\n";
86 printf "success.type COUNTER\n";
88 printf "referral.label Referral\n";
89 printf "referral.type COUNTER\n";
91 printf "nxrrset.label Nx RR set\n";
92 printf "nxrrset.type COUNTER\n";
94 printf "nxdomain.label NX domain\n";
95 printf "nxdomain.type COUNTER\n";
97 printf "recursion.label Recursion\n";
98 printf "recursion.type COUNTER\n";
100 printf "failure.label Failure\n";
101 printf "failure.type COUNTER\n";
106 if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) {
107 if (! -f $stat_file) {
108 printf "Unable to file bind stat file on %s",$stat_file;
112 printf "Unable to file rndc tool (configured : %s)",$rndc;
118 # Remove old stat file
120 # Ask to bind to build new one
122 # Parse the stat file and return result