#!/usr/bin/perl # # this is for after install use lib $ENV{'RRDPM'}; use RRDs; ################################## # SETUP ################################## # 1. Define the extention for the metric $ds = "benchmark"; @ds = ("DS:BENCHMARK:GAUGE:600:U:U"); ################################## # Start of script ################################## if( not $ENV{'BBHOME'} ) { print "$0: BBHOME is not set\n"; exit(1); } if( not -d $ENV{'BBHOME'} ) { print "$0: BBHOME is invalid\n"; exit(1); } if( not -d $ENV{'BBRRDS'} ) { print "$0: BBRRDS is not set\n"; exit(1); } ## # real work begins here ## # Glob the bind logs and data my %h_fn; # Perl Cookbook Recipe 9.5 opendir(DIR, "$ENV{'BBLOGS'}") or die "$0: $!"; while ( defined($log = readdir(DIR))) { next unless $log =~ /\.$ds$/io; my $host = $log; $host =~ s/\.$ds//; $host =~ s/\,/\./g; $h_fn{$host}="$ENV{'BBLOGS'}/$log"; } closedir(DIR); opendir(DIR, "$ENV{'BBVAR'}/data") or die "$0: $!"; while ( defined($log = readdir(DIR))) { next unless $log =~ /\.$ds$/io; my $host = $log; $host =~ s/\.$ds//; $host =~ s/\,/\./g; $h_fn{$host}="$ENV{'BBVAR'}/data/$log"; } closedir(DIR); # -------------------------------- # Benchmark real stuff starts here: # -------------------------------- # You must change the following values to reflect your architecture # and your wishes. # The purpose here is to be able to sort the statistics according # to the URIs. The RRDTool will produce one line on the graph # for each pattern. This way you can group URIs and have a view # of the "static" performance, the Tomcat performance, the # database performance, etc... # The key of the hash table is used as the text legend. my %urigroups = ( "Apache" => ".html\$|.doc\$|.pdf\$|.gif\$|.jpg\$|.png\$", "Tomcat" => ".srv\$|.jsp\$", "Oracle" => "^/test/", ); my %hits; my %totaltime; while ( ($host,$log) = each %h_fn ) { print "$0 : DEBUG log=$log\n" if ($ENV{'DEBUG'}); open(LOG,"$log"); #$temp = <LOG> if $log =~ /$ENV{'BBLOGS'}/io; ($ctime) = (stat($log))[10]; print "$0 : DEBUG ctime = $ctime\n" if ($ENV{'DEBUG'}); while (<LOG>) { # we manage with the lines made up of 7 columns only: @cols = split(/\s+/); if (scalar(@cols) != 7) { next; } $uri = @cols[6]; while (($key,$pattern) = each(%urigroups)) { if ($uri =~ $pattern) { $hits{$key} += @cols[0]; $totaltime{$key} += @cols[1]; } } } while (($key,$pattern) = each(%urigroups)) { if ($hits{$key} != 0) { $value = int($totaltime{$key} / $hits{$key}); } else { $value = 0; } $instance=",$key"; $RRD="$ENV{'BBRRDS'}/$host.$ds$instance.rrd"; print "$0 : RRD=$RRD\n" if ($ENV{'DEBUG'}); # see if the RRD is around, if not make it if ( not -f $RRD ) { # keeping this much disk data seems overkill # but thought 'standardizing' RRD's would be worth it # 30 seconds.... @rras = split " ",$ENV{'RRAS'}; RRDs::create($RRD,@ds,@rras); $ERR=RRDs::error; if($ERR) { print "$0: ERROR creating $RRD: $ERR\n" if ($ENV{'ERROR'}); next; #does this work? yup! } $ctime="N"; print "$0: STATUS did not find $RRD, created.\n" if ($ENV{'STATUS'}); } # now update the RRD RRDs::update("$RRD","$ctime:$value"); $ERR=RRDs::error; if($ERR) { print "$0: WARN updating $RRD: $ERR\n" if ($ENV{'WARN'}); } } unlink $log if $ENV{'LARRDCOMM'} =~ /DATA/i; } ############################################## # end of script ##############################################