Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / bind9 / bind9_rr @ 0ddf0181

Historique | Voir | Annoter | Télécharger (2,35 ko)

1
#!/usr/bin/perl -w
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
bind9_rr - Plugin to monitor usage of bind 9 servers
7

    
8
=head1 CONFIGURATION
9

    
10
This plugin is configurable environment variables.  The following
11
shows the default settings:
12

    
13
 [bind9_rr]
14
    env.logfile   /var/log/bind9/query.log
15

    
16
You must also configure query logging in your named.conf. Use a stanza
17
such as this:
18

    
19
 logging {
20
     channel query {
21
         file "query.log" versions 2 size 1m;
22
         print-time yes;
23
         severity info;
24
     };
25

    
26
     category queries { query; };
27
 };
28

    
29
=head1 SEE ALSO
30

    
31
=over
32

    
33
=item * L<http://blog.larsstrand.org/2008/02/how-to-monitor-bind-with-munin.html>
34

    
35
=item * BIND Administrator Reference Manual
36

    
37
=back
38

    
39
=head1 AUTHOR
40

    
41
Nicolai Langfeldt
42
Remi Paulmier
43

    
44
=head1 LICENSE
45

    
46
GPLv2
47

    
48
=head1 MAGIC MARKERS
49

    
50
  #%# family=manual
51

    
52
=cut
53

    
54
use strict;
55

    
56
my $QUERYLOG = $ENV{logfile} || '/var/log/bind9/query.log';
57
my $STATEFILE= "$ENV{MUNIN_PLUGSTATE}/bind9_rr.state";
58

    
59
my $OTHER=0;
60
my %IN;
61

    
62
sub get_state {
63
    if (! -f $STATEFILE) {
64
        open(Q, ">", $STATEFILE);
65
        close(Q);
66
    }
67
    open(Q,"< $STATEFILE") or die ("Cannot open state file");
68
    while (<Q>) {
69
        chomp;
70
        my ($q,$n) = split(/\s+/,$_,2);
71
        $IN{$q}=$n unless defined($IN{$q});
72
    }
73
    close(Q);
74
}
75

    
76

    
77
sub do_stats {
78
    my $k;
79

    
80
    open(Q,"< $QUERYLOG") or die "$!";
81
    while (<Q>) {
82
        chomp;
83
        if (/: (view \S+\: |)query\: (\S+) (\w+) (\w+)/) {
84
            if ($3 eq 'IN' and $4 !~ /^TYPE/) {
85
                my $crr = lc $2;
86
                $IN{$crr}++;
87
            } 
88
        }
89
    }
90
    close(Q);
91

    
92
    get_state;
93

    
94
    my @INkeys = sort { $IN{$b} <=> $IN{$a} } keys %IN;
95

    
96
    open(Q,"> $STATEFILE") or die;
97
    foreach $k (@INkeys[0 .. 19]) {
98
        next if not defined $k;
99
        my $l = $k; $k =~ tr/\./_/;
100
        print "rr_$k.value ",$IN{$l},"\n";
101
        print Q "$l ",$IN{$l},"\n";
102
    }
103
    close(Q);
104
}
105

    
106

    
107
sub do_config {
108
    my $k;
109

    
110
    print "graph_title DNS Queries by RR
111
graph_category BIND
112
graph_vlabel Queries / \${graph_period}
113
";
114
    get_state;
115

    
116
    my @INkeys = sort { $IN{$b} <=> $IN{$a} } keys %IN;
117

    
118
    foreach $k (@INkeys[0 .. 19]) {
119
        next if not defined $k;
120
        my $l = $k; $k =~ tr/\./_/;
121
        print "rr_$k.label $l
122
rr_$k.type DERIVE
123
rr_$k.min 0
124
rr_$k.draw STACK
125
";
126
    }
127
};
128

    
129
if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
130
    do_config;
131
    exit(0);
132
}
133

    
134
do_stats;
135

    
136

    
137
# vim:syntax=perl