root / plugins / bind / bind95_ @ fd2fb560
Historique | Voir | Annoter | Télécharger (4,28 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# |
| 3 |
# Copyright Jean-Samuel Reynaud <js.reynaud@free.fr> |
| 4 |
# Licensed under GPL v2 |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
bind95_ - Graph dns requests by type |
| 9 |
|
| 10 |
=head1 DESCRIPTION |
| 11 |
|
| 12 |
We use this script to produce graph with munin for dns requests. |
| 13 |
|
| 14 |
This version work with bind 9.5 |
| 15 |
|
| 16 |
Thanks to Benjamin Pineau for perl cleaning and corrections |
| 17 |
|
| 18 |
=head1 CONFIGURATION |
| 19 |
|
| 20 |
This script must have his name start with bind95_ |
| 21 |
|
| 22 |
=over 2 |
| 23 |
|
| 24 |
bind95_ : Global bind statistic |
| 25 |
bind95_test.com : Bind statistic for test.com zone (no view) |
| 26 |
bind95_test.com@internal : Bind statistic for test.com zone (view internal) |
| 27 |
|
| 28 |
=back |
| 29 |
|
| 30 |
You should have to add the following lines to you plugin configuration |
| 31 |
(/etc/munin/plugin-conf.d/munin-node): |
| 32 |
|
| 33 |
=over 2 |
| 34 |
|
| 35 |
[bind95_*] |
| 36 |
user root |
| 37 |
stat_file /var/cache/bind/named.stats |
| 38 |
rndc /usr/sbin/rndc |
| 39 |
|
| 40 |
=back |
| 41 |
|
| 42 |
=head1 MAGIC MARKERS |
| 43 |
|
| 44 |
#%# family=auto |
| 45 |
#%# capabilities=autoconf |
| 46 |
|
| 47 |
=head1 AUTHORS |
| 48 |
|
| 49 |
Jean-Samuel Reynaud <js.reynaud@free.fr> |
| 50 |
Andreas Perhab <a.perhab@wtioit.at> |
| 51 |
|
| 52 |
=head1 LICENSE |
| 53 |
|
| 54 |
GPLv2 |
| 55 |
|
| 56 |
=cut |
| 57 |
|
| 58 |
use strict; |
| 59 |
use warnings; |
| 60 |
use Digest::MD5 qw(md5_hex); |
| 61 |
|
| 62 |
# change those to reflect your bind configuration (use plugin configuration) |
| 63 |
# stat file |
| 64 |
my $stat_file = $ENV{'stat_file'} || "/var/cache/bind/named.stats";
|
| 65 |
# rndc path |
| 66 |
my $rndc = $ENV{'rndc'} || "/usr/sbin/rndc";
|
| 67 |
|
| 68 |
|
| 69 |
my $domain = $0; |
| 70 |
if ($domain =~ m/^.*bind95_[\w\d\._\-]+@[\w\d\._\-]+?$/) {
|
| 71 |
$domain =~ s/^.*bind95_([\w\d\._\-]*)@([\w\d\._\-]+)?$/$1 (view: $2)/; |
| 72 |
} elsif ($domain =~ m/^.*bind95_[\w\d\._\-]+$/) {
|
| 73 |
$domain =~ s/^.*bind95_([\w\d\._\-]+)$/$1/; |
| 74 |
} else {
|
| 75 |
$domain = "View: _bind"; |
| 76 |
} |
| 77 |
|
| 78 |
my @counters = ( |
| 79 |
'IPv4 requests received', |
| 80 |
'requests with EDNS(0) received', |
| 81 |
'TCP requests received', |
| 82 |
'auth queries rejected', |
| 83 |
'recursive queries rejected', |
| 84 |
'transfer requests rejected', |
| 85 |
'update requests rejected', |
| 86 |
'responses sent', |
| 87 |
'truncated responses sent', |
| 88 |
'responses with EDNS(0) sent', |
| 89 |
'queries resulted in successful answer', |
| 90 |
'queries resulted in authoritative answer', |
| 91 |
'queries resulted in non authoritative answer', |
| 92 |
'queries resulted in referral answer', |
| 93 |
'queries resulted in nxrrset', |
| 94 |
'queries resulted in SERVFAIL', |
| 95 |
'queries resulted in NXDOMAIN', |
| 96 |
'queries caused recursion', |
| 97 |
'duplicate queries received', |
| 98 |
'queries dropped', |
| 99 |
'other query failures', |
| 100 |
'requested transfers completed', |
| 101 |
'transfer requests succeeded', |
| 102 |
'IPv4 notifies sent', |
| 103 |
'IPv4 notifies received', |
| 104 |
'notifies rejected', |
| 105 |
'IPv4 SOA queries sent', |
| 106 |
'IPv4 IXFR requested' |
| 107 |
); |
| 108 |
|
| 109 |
|
| 110 |
# Parse the statistic file |
| 111 |
sub parseFile {
|
| 112 |
my @printed_counters = (); |
| 113 |
my $dom = shift @_; |
| 114 |
open(IN,"<$stat_file") or die "Can't open $stat_file : $!"; |
| 115 |
my $current_zone = ""; |
| 116 |
while (<IN>) {
|
| 117 |
chomp; |
| 118 |
my $l = $_; |
| 119 |
|
| 120 |
if ($l =~ /\[/ ) {
|
| 121 |
$l =~ s/\[//g; |
| 122 |
$l =~ s/\]//g; |
| 123 |
$current_zone = $l; |
| 124 |
} else {
|
| 125 |
$l =~ s/^ *//g; |
| 126 |
if ($l =~ /^[0-9]/ && $current_zone eq $domain) {
|
| 127 |
my ($val,$desc) = split(' ',$l,2);
|
| 128 |
if (grep { $desc eq $_ } @counters) {
|
| 129 |
printf "%s.value %u\n",md5_hex($desc),$val; |
| 130 |
push @printed_counters, $desc; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
close(IN); |
| 136 |
foreach(@counters) {
|
| 137 |
my $desc = $_; |
| 138 |
my @already_printed = grep { $desc eq $_ } @printed_counters;
|
| 139 |
if (!@already_printed) {
|
| 140 |
printf "%s.value 0\n", md5_hex($desc); |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
# Config mode |
| 148 |
if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) {
|
| 149 |
printf "graph_title Dns requests %s\n",($domain eq "View: _bind" ? " all domains":$domain); |
| 150 |
printf "graph_vlabel requests/s\n"; |
| 151 |
printf "graph_category dns\n"; |
| 152 |
printf "graph_info This graph display dns requests for %s\n",($domain eq "View: _bind" ? "all domains":$domain); |
| 153 |
|
| 154 |
foreach(@counters) {
|
| 155 |
my $s = $_; |
| 156 |
printf "%s.label %s\n",md5_hex($s),$s; |
| 157 |
printf "%s.type DERIVE\n",md5_hex($s); |
| 158 |
printf "%s.min 0\n",md5_hex($s); |
| 159 |
} |
| 160 |
exit 0; |
| 161 |
} |
| 162 |
|
| 163 |
if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) {
|
| 164 |
if (! -f $stat_file) {
|
| 165 |
printf "no (Unable to file bind stat file on %s)",$stat_file; |
| 166 |
exit 0; |
| 167 |
} |
| 168 |
if (! -f $rndc) {
|
| 169 |
printf "no (Unable to file rndc tool (configured : %s))",$rndc; |
| 170 |
exit 0; |
| 171 |
} |
| 172 |
exit 0; |
| 173 |
} |
| 174 |
|
| 175 |
# Remove old stat file |
| 176 |
unlink ($stat_file); |
| 177 |
# Ask to bind to build new one |
| 178 |
`$rndc stats`; |
| 179 |
# Parse the stat file and return result |
| 180 |
parseFile($domain); |
