File: bind9_rndc.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (81 lines) | stat: -rw-r--r-- 2,134 bytes parent folder | download | duplicates (3)
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
#!@@PERL@@ -w
# -*- perl -*-
# Plugin to monitor usage of bind 9 servers using rndc stats
#
# Contributed by Laurent Facq 15/06/2004
# Based on Nicolai Langfeldt bind9 plugin
# Reworked by Dagfinn Ilmari Mannsåker
#
# To intall, 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 plugin.
#
# Environment variables:
#	rndc		location of the rndc command.
#			set to empty if the stats are updated otherwise
#	querystats	location of the statistics file
#
# $Log$
# Revision 1.5  2004/12/15 18:05:40  ilmari
# - Don't use a state file (the statistics file is enough).
# - Make rndc and statistics file location configurable.
# - Linearize control flow.
# - General style cleanup.
#
#
#%# family=contrib

use strict;

my $rndc = defined($ENV{rndc}) ? $ENV{rndc} : '/usr/sbin/rndc';
my $querystats = $ENV{querystats} || '/var/run/named.stats';
my %IN;

system("$rndc stats") if $rndc;
    
open(my $stats, '<', $querystats) or die "$querystats: $!\n";
seek($stats , 400, -1);		# go nearly to the end of the file
				# to avoid reading it all

while (my $line = <$stats>) {
    chomp $line;

    # We want the last block like this in the file
    #+++ Statistics Dump +++ (1087277501)
    #success 106183673
    #referral 2103636
    #nxrrset 43534220
    #nxdomain 47050478
    #recursion 37303997
    #failure 17522313
    #--- Statistics Dump --- (1087277501)
	
    if ($line =~ m/\+\+\+ Statistics Dump \+\+\+/) {
	# reset
	undef %IN;
    } else {
	my ($what, $nb)= split('\s+', $line);
	if ($what && ($what ne '---')) {
	    $IN{$what} = $nb;
	}
    }
}
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";

    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;
}