/[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

Annotation of /parse_bind9stat.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Wed Jul 10 22:41:01 2002 UTC (16 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +24 -3 lines
File MIME type: text/plain
walk through dump file

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 1.5 my $log = shift @ARGV || "/var/log/stats.dump";
6 dpavlin 1.4 my $rndc = shift @ARGV || "/usr/sbin/rndc";
7 dpavlin 1.5 my $delta="/var/tmp/";
8 dpavlin 1.1
9 dpavlin 1.2 system "$rndc stats";
10 dpavlin 1.1
11     my @counters = qw(success referral nxrrset nxdomain recursion failure);
12    
13     my %total;
14     my %forward;
15     my %reverse;
16    
17 dpavlin 1.5 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 dpavlin 1.1 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 dpavlin 1.5 close(DUMP);
48    
49     open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
50     print D tell(DUMP);
51 dpavlin 1.1 close(D);
52    
53     foreach (@counters) {
54     print $total{$_},"\n",$forward{$_},"\n",$reverse{$_},"\n";
55     }

  ViewVC Help
Powered by ViewVC 1.1.26