/usr/share/munin/plugins/bind9_rndc is in munin-node 1.4.6-3ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | #!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
bind9_rndc - Plugin to monitor usage of bind 9 servers using rndc stats
=head1 CONFIGURATION
The following environment variables are used by this plugin
[bind_rndc]
env.rndc /usr/sbin/rndc
env.querystats /var/run/named.stats
The user/group that runs the plugin must have read access to the stats
file. To change user or group (usually Munin plugins are run as
nobody) add this to the [bind_rndc] stanza if the "bind" user runs
BIND:
user bind
On the BIND side put
statistics-file "/var/run/named.stats";
in the options part of your named.conf or set the querystats variable
(see below) to where your named puts the statistics file by default.
You must also make sure the rndc.key file is readable by the user that
runs the plugin.
=head1 FEATURES AND BUGS
Previous versions of this plugin allowed a empty "rndc" environment
setting to not do a explicit dump of stats to the stats file. This
version requires running rndc itself. This makes the method of
finding the correct stats in the file more reliable than before.
=head1 AUTHOR
Contributed by Laurent Facq 15/06/2004. Based on Nicolai Langfeldts
bind9 plugin. Reworked by Dagfinn Ilmari Mannsåker. BIND 9.6 patch
from "Vrivellino".
=head1 LICENSE
License not documented.
=head1 MAGIC MARKERS
#%# family=manual
=cut
use strict;
my $rndc = defined($ENV{rndc}) ? $ENV{rndc} : '/usr/sbin/rndc';
my $querystats = $ENV{querystats} || '/var/run/named.stats';
my %IN;
my $version96 = 0;
# check to see if we're running bind 9.6
if ( open VERSION, "$rndc 2>&1 |" ) {
while ( my $line = <VERSION> ) {
if ( $line =~ m/^Version:\s+9\.(\d+)\D/o ) {
$version96 = 1 if $1 >= 6;
}
}
}
# open the log file, and get its size
open(my $stats, '<', $querystats) or die "$0: $querystats: $!\n";
my $size = (stat $stats)[7];
# call rdnc and go directly to the correct offset
system("$rndc stats");
seek($stats , $size, 0);
# We want the last block like this in the file (bind 9.early)
#+++ Statistics Dump +++ (1087277501)
#success 106183673
#referral 2103636
#nxrrset 43534220
#nxdomain 47050478
#recursion 37303997
#failure 17522313
#--- Statistics Dump --- (1087277501)
# From BIND 9.5 or newer this is the format:
#
# +++ Statistics Dump +++ (1222740363)
# ++ Incoming Requests ++
# 13 QUERY
# ++ Incoming Queries ++
# 9 A
# 1 NS
# 1 SOA
# 1 MX
# 1 TXT
# ++ Outgoing Queries ++
# ++ Name Server Statistics ++
# 13 IPv4 requests received
# 13 responses sent
# 13 queries resulted in successful answer
# 9 queries resulted in authoritative answer
# 4 queries resulted in non authoritative answer
# 4 queries caused recursion
# ++ Zone Maintenance Statistics ++
# 6 IPv4 notifies sent
# --- Statistics Dump ---
if ( $version96 ) {
my $found_stats = 0;
while ( my $line = <$stats> ) {
chomp $line;
if ( $found_stats ) {
if ( $line =~ m/^\+\+/o ) {
$found_stats = 0;
next;
}
if ( $line =~ m/^\s+(\d+) (.*)$/o ) {
my $n = $1;
my $msg = $2;
if ($msg =~ m/requests received$/io) {
$IN{requests} = 0 unless $IN{requests};
$IN{requests} += $n;
} elsif ($msg =~ m/responses sent$/io ) {
$IN{responses} = 0 unless $IN{requests};
$IN{responses} += $n;
} elsif (lc $msg eq 'queries resulted in successful answer') {
$IN{success} = $n;
} elsif (lc $msg eq
'queries resulted in authoritative answer') {
$IN{auth_answer} = $n;
} elsif (lc $msg eq
'queries resulted in non authoritative answer') {
$IN{nonauth_answer} = $n;
} elsif (lc $msg eq 'queries resulted in nxrrset') {
$IN{nxrrset} = $n;
} elsif (lc $msg eq 'queries resulted in servfail') {
$IN{failure} = $n;
} elsif (lc $msg eq 'queries resulted in nxdomain') {
$IN{nxdomain} = $n;
} elsif (lc $msg eq 'queries caused recursion') {
$IN{recursion} = $n;
} elsif (lc $msg eq 'duplicate queries received') {
$IN{duplicates} = $n;
}
}
} elsif ( $line =~ m/^\+\+ Name Server Statistics \+\+$/o ) {
$found_stats = 1;
%IN = ( requests => 0,
responses => 0,
success => 0,
auth_answer => 0,
nonauth_answer => 0,
nxrrset => 0,
failure => 0,
nxdomain => 0,
recursion => 0,
duplicates => 0,
);
}
}
} else { # not version 9.6
while (my $line = <$stats>) {
chomp $line;
if ($line =~ m/\+\+\+ Statistics Dump \+\+\+/) {
# reset
undef %IN;
} else {
my ($what, $nb)= split('\s+', $line);
if ($what && ($what ne '---')) {
$IN{$what} = $nb;
}
}
next unless $line =~ /^(\w+) (\d+)$/;
$IN{$1} = $2;
}
}
close($stats);
if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
print "graph_title DNS Queries by status\n";
print "graph_vlabel queries / \${graph_period}\n";
print "graph_category BIND\n";
for my $key (keys %IN) {
print "query_$key.label $key\n";
print "query_$key.type DERIVE\n";
print "query_$key.min 0\n";
}
} else {
print "query_$_.value $IN{$_}\n" for keys %IN;
}
|