[Orca-dev] [PATCH] Web Server Hit Rate for procallator

Craig Sadler sadler at area51.sdsu.edu
Wed Jan 3 12:28:52 PST 2007


   * Additions allow procallator to access stats for http hits/sec and peak
     5 second accesses. The patch supplies an open-read-close to a file 
     updated by a helper application.

   * The helper application, "http_procallator.pl" supplied below, writes
     to a file one directory above the procallator data $DEST_DIR.
     The default procallator.cfg requires no change for this to work,
     though the http plot definition must be present.

   Patch by: Craig Sadler <sadler at sdsu.edu>
   Suggested by: Many.


--- procallator	2007-01-03 11:22:18.000000000 -0800
+++ procallator.new	2007-01-03 11:28:05.000000000 -0800
@@ -91,6 +91,9 @@
 my (@usr_100, @nice_100, @sys_100, @idle_100, @wait_100);
 my (@weightiotm, @ops_seq);
 
+# This section is http related 
+my ($httpops, $httpop5s);
+
 # This section looks to be ifconfig/nic.
 my (@if_name, @if_in_b, @if_in_p);
 my (@if_in_e, @if_in_d, @if_in_ff, @if_in_fr, @if_in_c);
@@ -222,6 +225,28 @@
         "15runq", $runq_15,   "#proc_oncpu", $proc_run,
         "#proc",  $procs[$r], "#proc/s",     rate(@procs)
     );
+    
+#########################################################################
+## The following code and the additions on or around line 92-93
+## allow procallator to access stats for http hits/sec. An external
+## script "http_procallator.pl" accesses the http log and writes 
+## the default 5 minute average number of hits and the largest of the 5 
+## second peaks. 
+###Begin Web Requests####################################################
+
+    # Read http requests
+    open (F_HTTP_REQ, "$DEST_DIR/../http.dat")
+          or die "$0: cannot open http dat for reading: $!";
+ 
+    ($httpops, $httpop5s) =  split(/:/,<F_HTTP_REQ>);
+    close(F_HTTP_REQ);
+    
+    print STDERR ("HTTP Reads:",($httpops,,":", $httpop5s),"\n" ) if $DEBUG;
+    chomp($httpop5s);
+    put_output(
+        "httpop/s",  ($httpops),  "http/p5s",  $httpop5s
+    );
+#####End Web Requests######################################################
 
     # Read system stats
     open(F_STAT, "$PROC/stat")

*** End Patch ***

*** begin http_procallator.pl helper app *** 

#!/usr/bin/perl -w
#############################
## This is a helper App for procallator to allow procallator to report 
## "Web Server Hit Rate" in the same way that orcallator for Solaris does. 
## Using the File::Tail Module this helper watches a log file and records 
## the number of lines in the log file over "interval_time" (default is 300 
## seconds) along with recording the number of lines in the log file (hits)
## every 5 seconds within the "interval_time". At the end of the 
## "interval_time", the total new lines recorded to the log are divided 
## by the "interval_time", which gives the average hit rate over 5 minutes
## and the largest number of hits among the 5 second or peak intervals.
## These two numbers are written to a file and the file is read by a patched
## version of procallator in the usual way. No change is needed to the 
## default procallator.cfg file. File::Tail takes care of server log rotation.
#####################################################
$| = 1;
use strict;
use File::Tail;
my @peak;
my %cfg = (
  #rate_file      => "@VAR_DIR@/procallator/$HOSTNAME/http.dat",
  #httpd_log      => "@WEB_LOG@",
  rate_file      => "/var/lib/orca/procallator/http.dat",
  httpd_log      => '/opt/www/logs/access_log',
  interval_time  => 300,
  peak_interval  => 5,
  debug          => 0,
);
my %dat = (
  interval_count => 0,
  interval_start => 0,
  interval_mark  => 0,
  peak5s_count   => 0,
  peak5s_start   => 0,
  peak5s_mark    => 0,
  avg_rp5s       => 0,
  high5s         => 0,
  rps            => 0,
  rps_final      => 0,
);
 my $tailed_file=File::Tail->new(name=>$cfg{httpd_log}, 
		       interval=>3, 
		       maxinterval=>30, 
		       adjustafter=>3,
) 
   or die("could not open $dat{httpd_log} for tail");

 while (defined(my $line=$tailed_file->read)) {

      print " . " if ($cfg{debug});

   $dat{interval_count}++;
   $dat{interval_start}  = time if ($dat{interval_start} == 0);
   $dat{interval_mark}   = time; 
   $dat{peak5s_count}++;
   $dat{peak5s_start}    = time if ($dat{peak5s_start} == 0);
   $dat{peak5s_mark}     = time;

   if (($dat{peak5s_mark}- $dat{peak5s_start} ) >= $cfg{peak_interval}) {

     print " .. 5 sec .. " if ($cfg{debug});

     push @peak, $dat{peak5s_count};

     $dat{peak5s_count} = 0;
     $dat{peak5s_start} = 0;
     $dat{peak5s_mark}  = 0;
   }
   if (($dat{interval_mark} - $dat{interval_start}) >= $cfg{interval_time}) {

     print " ... 5 min ... " if ($cfg{debug});

     $dat{rps} = 
         ($dat{interval_count}/($dat{interval_mark}-$dat{interval_start}));
     $dat{interval_count} = 0;
     $dat{interval_start} = "0";

     $dat{avg_rp5s}  = 0;
     $dat{high5s}    = 0;

     foreach my $memb (@peak){
       $dat{high5s}  =  ($dat{high5s}  + $memb);
     }
     @peak = ();

     print "peak5s: $dat{high5s} \n" if ($cfg{debug});

     $dat{avg_rp5s} = sprintf( "%.3f", 
                     ($dat{high5s}/($cfg{interval_time}/$cfg{peak_interval}))
     );

     $dat{rps_final} = sprintf ( "%.3f", $dat{rps});

     open (LAST, "+>$cfg{rate_file}") or die "could not open $cfg{rate_file}";
     print LAST  "$dat{rps_final}:$dat{avg_rp5s}";
     close LAST;
     print "$dat{rps_final}:$dat{avg_rp5s}"  if ($cfg{debug});
   } 
}



More information about the Orca-dev mailing list