File: bind9.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (134 lines) | stat: -rw-r--r-- 2,256 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
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
#!@@PERL@@ -w
# -*- perl -*-

=head1 NAME

bind9 - Plugin to monitor usage of bind 9 servers

=head1 CONFIGURATION

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

 [bind9]
    env.logfile   /var/log/bind9/query.log

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

 logging {
     channel query {
         file "query.log" versions 2 size 1m;
         print-time yes;
         severity info;
     };

     category queries { query; };
 };

=head1 SEE ALSO

=over

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

=item * BIND Administrator Reference Manual

=back

=head1 AUTHOR

Nicolai Langfeldt

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

  #%# family=manual

=cut

use strict;

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

my $OTHER=0;
my %IN;

sub get_state {
    if (! -f $STATEFILE) {
        open(Q, ">", $STATEFILE);
        close(Q);
    }
    open(Q,"< $STATEFILE") or die ("Cannot open state file");
    while (<Q>) {
        chomp;
        my ($q,$n) = split(/\s+/,$_,2);
        $IN{$q}=$n unless defined($IN{$q});
    }
    close(Q);
}


sub do_stats {
    my $k;

    open(Q,"< $QUERYLOG") or die "$!";
    while (<Q>) {
        chomp;
        if (/: (view \S+\: |)query\: \S+ (\w+) (\w+)/) {
            if ($2 eq 'IN' and $3 !~ /^TYPE/) {
                $IN{$3}++;
            } else {
                $OTHER++;
            }
        }
    }
    close(Q);

    get_state;

    open(Q,"> $STATEFILE") or die;
    foreach $k (sort keys %IN) {
        print "query_$k.value ",$IN{$k},"\n";
        print Q "$k ",$IN{$k},"\n";
    }
    close(Q);

    print "query_other.value ",$OTHER,"\n";
}


sub do_config {
    my $k;

    print "graph_title DNS Queries by type
graph_category dns
graph_vlabel Queries / \${graph_period}
";
    get_state;

    foreach $k (sort keys %IN) {
        print "query_$k.label $k
query_$k.type DERIVE
query_$k.min 0
";
    }
    print "query_other.label Other
query_other.type DERIVE
query_other.min 0
";
};

if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
    do_config;
    exit(0);
}

do_stats;


# vim:syntax=perl