Initial check-in.
[monitoring/munin.git] / bind95
1 #!/usr/bin/perl
2 #
3 # Copyright Jean-Samuel Reynaud <js.reynaud@free.fr>
4 # Licenced under GPL v2
5 #
6 # We use this script to produce graph with munin for dns requests
7 #
8 # Thanks for Benjamin Pineau for perl cleaning and correction in non root
9 # running
10 #
11 # modified for bind 9.5 by -thh 2009-04-15
12 #
13 # Magic markers
14 #%# family=auto
15 #%# capabilities=autoconf
16
17 use strict;
18 use warnings;
19
20 # change those to reflect your bind configuration
21 # stat file
22 my $stat_file = "/var/log/named/stats";
23 # rndc path
24 my $rndc = "/usr/sbin/rndc";
25
26
27
28 my $lst = { "success" => 1,
29             "referral" => 1,
30             "nxrrset" => 1,
31             "nxdomain" => 1,
32             "recursion" => 1,
33             "failure" => 1};
34
35 #my $domain = $0;
36 #$domain =~ s/^.*bind_([\w\d\._\-]*)$/$1/;
37 my $domain = '';
38
39
40 # Parse the statistic file
41 sub parseFile {
42     my $dom = shift @_;
43     open(IN,"<$stat_file") or die "Can't open $stat_file : $!";
44
45     while (<IN>) {
46         chomp;
47         s/^ *//; 
48         my ($count,@type) = split(/ /,$_);
49         my $type = join(' ',@type);
50         #$zone = defined($zone) ? $zone : "";
51         #if ($zone eq $dom) {
52         #    if (defined $lst->{$type}) {
53         #        # only keep the latest occurence for each value
54         #        $lst->{$type} = $count;
55         #    }
56         #
57         #}
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;
70         }
71     }
72
73     close(IN);
74     printf "%s.value %u\n", $_, $lst->{$_} foreach (keys %$lst);
75 }
76
77
78
79 # Config mode
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";
87
88     printf "referral.label Referral\n";
89     printf "referral.type COUNTER\n";
90
91     printf "nxrrset.label Nx RR set\n";
92     printf "nxrrset.type COUNTER\n";
93
94     printf "nxdomain.label NX domain\n";
95     printf "nxdomain.type COUNTER\n";
96
97     printf "recursion.label Recursion\n";
98     printf "recursion.type COUNTER\n";
99
100     printf "failure.label Failure\n";
101     printf "failure.type COUNTER\n";
102
103     exit 0;
104 }
105
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;
109         exit 1;
110     }
111     if (! -f $rndc) {
112         printf "Unable to file rndc tool (configured : %s)",$rndc;
113         exit 1;
114     }
115     exit 0;
116 }
117
118 # Remove old stat file
119 unlink ($stat_file);
120 # Ask to bind to build new one
121 `$rndc stats`;
122 # Parse the stat file and return result
123 parseFile($domain);
124
This page took 0.012648 seconds and 3 git commands to generate.