Projet

Général

Profil

Révision e3e3ca27

IDe3e3ca2787279291ebbde0404f705a9f28a411c2
Parent 84866ca6
Enfant 0ddf0181

Ajouté par Rémi Paulmier il y a presque 12 ans

added a new plugin to monitor bind9 usage by RR queried

Voir les différences:

plugins/bind9/bind9_rr
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
        print "rr_$k.value ",$IN{$k},"\n";
99
        print Q "$k ",$IN{$k},"\n";
100
    }
101
    close(Q);
102
}
103

  
104

  
105
sub do_config {
106
    my $k;
107

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

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

  
116
    foreach $k (@INkeys[0 .. 19]) {
117
        print "rr_$k.label $k
118
rr_$k.type DERIVE
119
rr_$k.min 0
120
rr_$k.draw STACK
121
";
122
    }
123
};
124

  
125
if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
126
    do_config;
127
    exit(0);
128
}
129

  
130
do_stats;
131

  
132

  
133
# vim:syntax=perl

Formats disponibles : Unified diff