<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>[Omaha.pm] IIS server log analysis</TITLE>
</HEAD>
<BODY>
<DIV id=idOWAReplyText28443 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2><A
href="http://sqljunkies.com/WebLog/ktegels/archive/2003/12/05/580.aspx">http://sqljunkies.com/WebLog/ktegels/archive/2003/12/05/580.aspx</A></FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> omaha-pm-bounces@pm.org on behalf of Jay
Hannah<BR><B>Sent:</B> Tue 3/22/2005 7:26 PM<BR><B>To:</B> Omaha Perl
Mongers<BR><B>Subject:</B> [Omaha.pm] IIS server log
analysis<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2> From the Why Didn't I Post This Yesterday To Let Someone
Else Do My <BR>Homework For Me
Department<BR><BR>-----------------<BR>PROBLEM<BR>-----------------<BR><BR>Given
a directory of .zip
files:<BR><BR>ex050220.zip<BR>ex050221.zip<BR>ex050222.zip<BR>ex050223.zip<BR>ex050224.zip<BR>ex050225.zip<BR>ex050226.zip<BR><BR>Containing
IIS server logs like this:<BR><BR># Fields: date time c-ip cs-username s-ip
s-port cs-method cs-uri-stem <BR>cs-uri-query sc-status sc-bytes
cs(User-Agent) cs(Cookie) cs(Referer)<BR>2005-02-20 00:00:00 68.60.191.239 -
198.64.145.249 443 GET <BR>/images/header/tnd_sg_07-over.gif - 304
163 <BR>Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) <BR>ASPSESSIONIDSCSSSCRD=OAMAHBPAJHHBGEJEKBALFCOO <BR><A
href="https://ssl.omnihotels.com/Omni">https://ssl.omnihotels.com/Omni</A>?<BR>prop=CHIDTN&pagedst=AvailReq&pagesrc=Hotels<BR>...<BR><BR>Report
the total number of bytes per hour transferred from port 80 and <BR>port
443 like so:<BR><BR>Year to hour Port 80 Port
443<BR>------------- --------- -----------<BR>2005-02-20-00 208867846
31587703<BR>2005-02-20-01 193477261 25950887<BR>2005-02-20-02 210614224
24952027<BR>...<BR><BR>-----------------<BR>SOLUTION<BR>-----------------<BR><BR>for
(20 .. 26) {<BR> # Shooting for:
ex050220.log<BR> $file = sprintf("ex0502%d",
$_);<BR> `unzip $file.zip`;<BR>
readfile("$file.log");<BR>
unlink("$file.log");<BR>}<BR><BR>sub readfile {<BR> my ($file)
= @_;<BR> my %stats;<BR> open (IN,
$file);<BR> while (<IN>)
{<BR> next if
/^#/;<BR> my @l = split /
/;<BR> $hour =
$l[1];<BR> $hour =~
s/:.*//;<BR> $stats{"$l[0]-$hour"}{$l[5]} +=
$l[10];<BR>
#$cnt++;<BR> #last if ($cnt ==
500);<BR> }<BR> close
IN;<BR><BR> foreach (sort keys %stats)
{<BR> print "$_ $stats{$_}{80}
$stats{$_}{443}\n";<BR>
}<BR>}<BR><BR><BR>_______________________________________________<BR>Omaha-pm
mailing list<BR>Omaha-pm@pm.org<BR><A
href="http://mail.pm.org/mailman/listinfo/omaha-pm">http://mail.pm.org/mailman/listinfo/omaha-pm</A><BR></FONT></P></DIV>
</BODY>
</HTML>