Date: Thu, 24 Nov 1994 03:20:34 +0100
Message-Id: <Pine.3.89.9411241339.C3558-0100000@miriworld.its.unimelb.edu.au>
From: "Daniel O'Callaghan" <danny@miriworld.its.unimelb.EDU.AU>
To: Multiple recipients of list <www-proxy@www0.cern.ch>
Subject: Perl script for analysing cache stats
Here is a perl script for analysing cache stats. It is pretty basic.
If anyone has written anything better, please let me know.
The output is in the form:
Cache statistics for the period 20/Nov/1994:04:18:07 to 24/Nov/1994:10:58:50
------------------------------------------------------------------------
External Fetches : 9461 Bytes: 195411810
Fetches from cache: 2794 Bytes: 34850033
Total requests : 12255
Percentage cache hit rate: 22.8 % hits, 15.1 % bytes
Danny
==================================================================
#!/usr/local/bin/perl
#
# This script is used to analyse a log file of a caching proxy WWW
# server. It excludes documents local the the CPS, and also
# excludes documents in your local domain. That is, it only
# looks at requests for documents which are external to your site,
# and the cached versions of those documents.
# It operates on COMMON log file format. It will only work if you
# are logging cache requests to a separate file.
#
# Variables which need to be preset:
#
# $domain = your local top level domain e.g. unimelb.edu.au
# $logfile = Where requests for external documents are logged
# $cachelogfile = Where requests satisfied from the cache are logged
#
$domain='unimelb.edu.au|mu.oz.au';
$logfile='/cern/its-log';
$cachelogfile='/cern/its-cache-log';
# $realdoc is the start of a request for a real document on this server,
# to differentiate from method requests
#
$realdoc= '\"GET \/';
open( LOG, $logfile );
while( <LOG>)
{
chop;
if(! /$realdoc/)
{
@LOG=split(/ /);
$ldate=$LOG[3];
if( $date eq "" ){ # save the first date in the log
$date=$ldate;
$date=~s/\[//;
}
$_=$LOG[6];
if( ! /$domain/ ) # the requested doc is not internal
{
$extcount++; # count the external fetches
}
}
if( $LOG[8]==200 ){ $extbytes+=$LOG[9];}
}
close (LOG);
$ldate=~s/\[//;
open( LOG, "$cachelogfile" );
while( <LOG>)
{
$hitcount++; # count the cache hits
@LOG=split(/ /);
if( $LOG[8]==200 )
{
$cachebytes+=$LOG[9];
}
}
$total=$hitcount+$extcount;
$percent=100*$hitcount/$total;
$percentbytes=100*$cachebytes/($cachebytes+$extbytes);
print "Cache statistics for the period $date to $ldate\n";
print
"------------------------------------------------------------------------\n";
print "External Fetches : $extcount Bytes: $extbytes\n";
print "Fetches from cache : $hitcount Bytes: $cachebytes\n";
print "Total requests : $total\n";
printf( "Percentage cache hit rate: %5.1f %% hits, %5.1f %% bytes\n",
$percent, $percentbytes);
print "\n\n";