/[cricket]/parse_bind9stat.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /parse_bind9stat.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Fri Jul 26 10:10:02 2002 UTC (17 years, 4 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +6 -0 lines
File MIME type: text/plain
better instruction on top of file

1 #!/usr/bin/perl -w
2
3 # Parse output from bind9 rndc stats command
4 # Dobrica Pavlinusic, <dpavlin@rot13.org>
5 # http://www.rot13.org/~dpavlin/sysadm.html
6 #
7 # Usage: parse_bind9stat.pl [/var/log/stats.dump [/usr/sbin/rndc]]
8
9 use strict;
10
11 my $log = shift @ARGV || "/var/log/stats.dump";
12 my $rndc = shift @ARGV || "/usr/sbin/rndc";
13 my $delta="/var/tmp/";
14
15 system "$rndc stats";
16
17 my @counters = qw(success referral nxrrset nxdomain recursion failure);
18
19 my %total;
20 my %forward;
21 my %reverse;
22
23 my $tmp=$log;
24 $tmp=~s/\W/_/g;
25 $delta.=$tmp.".offset";
26
27 open(DUMP,$log) || die "$log: $!";
28
29 if (-e $delta) {
30 open(D,$delta) || die "can't open delta file '$delta' for '$log': $!";
31 my $offset=<D>;
32 chomp $offset;
33 close(D);
34 my $log_size = -s $log;
35 if ($offset <= $log_size) {
36 seek(DUMP,$offset,0);
37 }
38 }
39
40 while(<DUMP>) {
41 next if /^(---|\+\+\+)/;
42 chomp;
43 my ($what,$nr,$direction) = split(/\s+/,$_,3);
44 if (! $direction) {
45 $total{$what} += $nr;
46 } elsif ($direction =~ m/in-addr.arpa/) {
47 $reverse{$what} += $nr;
48 } else {
49 $forward{$what} += $nr;
50 }
51
52 }
53
54 open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
55 print D tell(DUMP);
56 close(D);
57
58 close(DUMP);
59
60 foreach (@counters) {
61 print $total{$_},"\n",$forward{$_},"\n",$reverse{$_},"\n";
62 }

  ViewVC Help
Powered by ViewVC 1.1.26