/[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.6 - (show annotations)
Wed Jul 10 22:44:31 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +2 -1 lines
File MIME type: text/plain
don't close dump file too early

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

  ViewVC Help
Powered by ViewVC 1.1.26