root / plugins / network / bind_ @ dd4afac8
Historique | Voir | Annoter | Télécharger (3,01 ko)
| 1 | dd74f0f6 | Jean-Samuel Reynaud | #!/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 | # This script must have his name start with bind_ |
||
| 8 | # bind_ : Global bind statistic |
||
| 9 | # bind_test.com : Bind statistic for test.com zone |
||
| 10 | # |
||
| 11 | # "env.bind_stat_file" is the path to the bind statistic file |
||
| 12 | # (/var/cache/bind/named.stats by default). |
||
| 13 | # |
||
| 14 | # "env.bind_rndc" is the path to the rndc tool |
||
| 15 | # (/usr/sbin/rndc by default). |
||
| 16 | # |
||
| 17 | # Thanks for Benjamin Pineau for perl cleaning and correction in non root |
||
| 18 | # running |
||
| 19 | # Thanks to Immanuel Klinkenberg for adding config parameter by using munin config |
||
| 20 | # |
||
| 21 | # Magic markers |
||
| 22 | #%# family=auto |
||
| 23 | #%# capabilities=autoconf |
||
| 24 | |||
| 25 | use strict; |
||
| 26 | use warnings; |
||
| 27 | |||
| 28 | # change those to reflect your bind configuration |
||
| 29 | # stat file |
||
| 30 | my $stat_file = # DB directory |
||
| 31 | defined $ENV{'bind_stat_file'} ? $ENV{'bind_stat_file'} : '/var/cache/bind/named.stats';
|
||
| 32 | # rndc path |
||
| 33 | my $rndc = # rndc path |
||
| 34 | defined $ENV{'bind_rndc'} ? $ENV{'bind_rndc'} : '/usr/sbin/rndc';
|
||
| 35 | |||
| 36 | my $lst = { "success" => 1,
|
||
| 37 | "referral" => 1, |
||
| 38 | "nxrrset" => 1, |
||
| 39 | "nxdomain" => 1, |
||
| 40 | "recursion" => 1, |
||
| 41 | "failure" => 1}; |
||
| 42 | |||
| 43 | my $domain = $0; |
||
| 44 | $domain =~ s/^.*bind_([\w\d\._\-]*)$/$1/; |
||
| 45 | |||
| 46 | |||
| 47 | # Parse the statistic file |
||
| 48 | sub parseFile {
|
||
| 49 | my $dom = shift @_; |
||
| 50 | open(IN,"<$stat_file") or die "Can't open $stat_file : $!"; |
||
| 51 | |||
| 52 | while (<IN>) {
|
||
| 53 | chomp; |
||
| 54 | my ($type,$count,$zone) = split(/ /,$_); |
||
| 55 | $zone = defined($zone) ? $zone : ""; |
||
| 56 | if ($zone eq $dom) {
|
||
| 57 | if (defined $lst->{$type}) {
|
||
| 58 | # only keep the latest occurence for each value |
||
| 59 | $lst->{$type} = $count;
|
||
| 60 | } |
||
| 61 | |||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | close(IN); |
||
| 66 | printf "%s.value %u\n", $_, $lst->{$_} foreach (keys %$lst);
|
||
| 67 | } |
||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | # Config mode |
||
| 72 | if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) {
|
||
| 73 | printf "graph_title Dns requests %s\n",($domain eq "" ? " all domains":$domain); |
||
| 74 | printf "graph_vlabel requests/s\n"; |
||
| 75 | printf "graph_category network\n"; |
||
| 76 | printf "graph_info This graph display dns requests for %s\n",($domain eq "" ? " all domains":$domain); |
||
| 77 | printf "success.label Success\n"; |
||
| 78 | printf "success.type COUNTER\n"; |
||
| 79 | |||
| 80 | printf "referral.label Referral\n"; |
||
| 81 | printf "referral.type COUNTER\n"; |
||
| 82 | |||
| 83 | printf "nxrrset.label Nx RR set\n"; |
||
| 84 | printf "nxrrset.type COUNTER\n"; |
||
| 85 | |||
| 86 | printf "nxdomain.label NX domain\n"; |
||
| 87 | printf "nxdomain.type COUNTER\n"; |
||
| 88 | |||
| 89 | printf "recursion.label Recursion\n"; |
||
| 90 | printf "recursion.type COUNTER\n"; |
||
| 91 | |||
| 92 | printf "failure.label Failure\n"; |
||
| 93 | printf "failure.type COUNTER\n"; |
||
| 94 | |||
| 95 | exit 0; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) {
|
||
| 99 | if (! -f $stat_file) {
|
||
| 100 | printf "Unable to file bind stat file on %s",$stat_file; |
||
| 101 | exit 1; |
||
| 102 | } |
||
| 103 | if (! -f $rndc) {
|
||
| 104 | printf "Unable to file rndc tool (configured : %s)",$rndc; |
||
| 105 | exit 1; |
||
| 106 | } |
||
| 107 | exit 0; |
||
| 108 | } |
||
| 109 | |||
| 110 | # Remove old stat file |
||
| 111 | unlink ($stat_file); |
||
| 112 | # Ask to bind to build new one |
||
| 113 | `$rndc stats`; |
||
| 114 | # Parse the stat file and return result |
||
| 115 | parseFile($domain); |
