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

Diff of /parse_bind9stat.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dpavlin, Mon Jul 1 19:55:38 2002 UTC revision 1.7 by dpavlin, Fri Jul 26 10:10:02 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/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;  use strict;
10    
11  my $bind9_dump = shift @_ || "/var/log/stats.dump";  my $log = shift @ARGV || "/var/log/stats.dump";
12  my $rndc = shift @_ || "/usr/sbin/rndc";  my $rndc = shift @ARGV || "/usr/sbin/rndc";
13    my $delta="/var/tmp/";
14    
15  system "$rndc stats";  system "$rndc stats";
16    
# Line 13  my %total; Line 20  my %total;
20  my %forward;  my %forward;
21  my %reverse;  my %reverse;
22    
23  open(D,$bind9_dump) || die "$bind9_dump: $!";  my $tmp=$log;
24  while(<D>) {  $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 /^(---|\+\+\+)/;          next if /^(---|\+\+\+)/;
42          chomp;          chomp;
43          my ($what,$nr,$direction) = split(/\s+/,$_,3);          my ($what,$nr,$direction) = split(/\s+/,$_,3);
# Line 27  while(<D>) { Line 50  while(<D>) {
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);  close(D);
57    
58    close(DUMP);
59    
60  foreach (@counters) {  foreach (@counters) {
61          print $total{$_},"\n",$forward{$_},"\n",$reverse{$_},"\n";          print $total{$_},"\n",$forward{$_},"\n",$reverse{$_},"\n";
62  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26