]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
log file stats parse perl script from Kai Storbeck.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 10 Apr 2008 10:18:44 +0000 (10:18 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 10 Apr 2008 10:18:44 +0000 (10:18 +0000)
git-svn-id: file:///svn/unbound/trunk@1027 be551aaa-1e26-0410-a405-d3ace91eadb9

contrib/README
contrib/parseunbound.pl [new file with mode: 0644]
doc/Changelog

index 3fecea173c251db7b1e5ee7f89d0b907b1bac77c..8c7490355d92a0b6f4719fdd050c7b256dae3baf 100644 (file)
@@ -2,3 +2,5 @@ These files are contributed to unbound, and are not part of the official
 distribution but may be helpful.
 
 * rc_d_unbound: FreeBSD compatible /etc/rc.d script.
+* parseunbound.pl: perl script to run from cron that parses statistics from
+       the log file and stores them.
diff --git a/contrib/parseunbound.pl b/contrib/parseunbound.pl
new file mode 100644 (file)
index 0000000..b1a691e
--- /dev/null
@@ -0,0 +1,102 @@
+#!/usr/local/bin/perl -w
+use strict;
+use POSIX qw(SEEK_END);
+use Storable;
+use FileHandle;
+use Data::Dumper;
+use Carp qw(croak carp);
+use constant UNBOUND_CACHE => "/var/tmp/unbound-cache.stor";
+
+my $run_from_cron = @ARGV && $ARGV[0] eq "--cron" && shift;
+my $DEBUG = -t STDERR;
+
+### if cache exists and  is newer than 3 minutes
+if ( -r UNBOUND_CACHE && -M _ < 3/24/60 && !$run_from_cron ) {
+       print STDERR "Cached results:\n" if $DEBUG;
+       my $result = retrieve(UNBOUND_CACHE);
+       print join("\n", @$result), "\n";
+       exit;
+}
+
+my $logfile = shift or die "Usage: parseunbound.pl --cron unboundlogfile";
+my $in = new FileHandle $logfile or die "Cannot open $logfile: $!\n";
+$in->seek(-2500, SEEK_END) or croak "cannot seek $logfile: $!\n";
+
+# Stats array containing 1 or more stats hashes.
+my @totalstats = ();
+# Each stats hash contains name/value pairs of the actual numbers for that thread.
+# there is a special key 'thread' that indicates the thread.
+my $stats = {};
+my $inblock = 0;
+my @records = ('thread', 'queries', 'answers', 'recursions', 'recursionavg',
+               'outstandingmax', 'outstandingavg', 'outstandingexc',
+               'us_0', 'us_128', 'us_256', 'us_512', 'us_1024', 'us_2048', 'us_4096', 'us_8192',
+               'us_16384', 'us_32768', 'us_65536', 'us_131072', 'us_262144', 'us_524288',
+               'ms_1', 'ms_2', 'ms_4', 'ms_8', 'ms_16', 'ms_32', 'ms_64', 'ms_256', 'ms_128','ms_512');
+
+
+for my $line ( <$in> ) {
+       chomp($line);
+       #print ">> $line\n";
+
+       if ( !$inblock && $line =~ m/info: server stats for thread (\d+): (\d+) queries, (\d+) answers from cache, (\d+) recursions/ ) {
+               $inblock = 1;
+               # NB: this clears the previous stats
+               $stats = {
+                       thread => $1,
+                       queries => $2,
+                       answers => $3,
+                       recursions => $4,
+               };
+               #print STDERR "Parsing stats from thread " . $stats->{thread} . "\n"; 
+       }
+       elsif ( $inblock && $line =~ m/info: server stats for thread (\d+): requestlist max (\d+) avg ([0-9\.]+) exceeded (\d+)/ ) {
+               $stats->{outstandingmax} = $2;
+               $stats->{outstandingavg} = $3;
+               $stats->{outstandingexc} = $4;
+       }
+       if ( $inblock && $line =~ m/info: average recursion processing time ([0-9\.]+) sec/ ) {
+               $stats->{recursionavg} = $1;
+       }
+       if ( $inblock && $line =~ m/info: histogram of recursion processing times/ ) {
+               next;
+       }
+       if ( $inblock && $line =~ m/info: [25%]=([0-9\.]+) median[50%]=([0-9\.]+) [75%]=([0-9\.]+)/ ) {
+               $stats->{median25} = $1;
+               $stats->{median50} = $2;
+               $stats->{median75} = $3;
+       }
+       if ( $inblock && $line =~ m/info: lower(secs) upper(secs) recursions/ ) {
+               next;
+       }
+       elsif ( $inblock && $line =~ m/info:\s+(\d+)\.(\d+)\s+(\d+)\.(\d+)\s+(\d+)/ ) {
+               my ($fromms, $fromus, $toms, $tous, $counter) = ($1, $2, $3, $4, $5);
+               my $prefix = '';
+               if ($fromms > 0) {
+                       $stats->{'ms_' . int($fromms)} = $counter;
+               } else {
+                       $stats->{'us_' . int($fromus)} = $counter;
+               }
+               if ($fromms == '512') {
+                       $inblock = 0;
+                       #push @totalstats, $stats;
+                       # or print $stats.
+               }
+       }
+       else {
+               #print STDERR "Cannot parse line: $line (unexpected, inblock=$inblock)\n";
+       }
+}
+
+if ( ! $stats ) {
+       die "Couldn't parse stats?!\n";
+}
+
+my @result;
+for my $key ( @records ) {
+       print STDERR "$key = " . $stats->{$key} . "\n";
+       push @result, $stats->{$key};
+}
+print join("\n", @result), "\n";
+store \@result, UNBOUND_CACHE;
+
index a390f6f00719fb46d8c4cee5450bde7bc21b51a2..ef939e89cc475b49e0d2d361f43e9797cf22b668 100644 (file)
@@ -1,5 +1,6 @@
 10 April 2008: Wouter
        - --with-libevent works with latest libevent 1.4.99-trunk.
+       - added log file statistics perl script to contrib.
 
 9 April 2008: Wouter
        - configure can detect libev(from its build directory) when passed