#!/usr/bin/perl -w # httpsum.pl,v 1.4 1999/09/25 06:23:12 wessels Exp $cutoff=50; $curtime=time(); # get current time stamp $hostname = shift || die "usage: $0 servername\n"; $thcount = $tdoccount = $uniqdoccnt = 0; while(<>) { next unless (/(\S+) \S+ \S+ \[[^\]]+\] "([^"]+)" \S+ (\S+)/); $from = $1; $request = $2; $size = $3; next unless ($request =~ /\S+\s+(\S+)/); $what = $1; $doccnt{$what}++; if(!$dochst{$what,$from}){$dochstcnt{$what}++;} $dochst{$what,$from}=1; $hcount{$from}++; $tdoccount++; &directory_bytes($what,$size); $client_bytes_hash{$from} += $size unless ($size eq '-'); } foreach $key (keys %hcount){$thcount++;} foreach $key (keys %doccnt){$uniqdoccnt++;} ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($curtime); printf "HTTP server summary on $hostname at %d/%02d/%02d %.2d:%.2d:%.2d\n\n", $year+1900,$mon+1,$mday, $hour,$min,$sec; $yday = $wday = $isdst = 0; # shut up perl -w printf"Total of $tdoccount documents ($uniqdoccnt unique) accessed by $thcount hosts\n\n"; printf "Top $cutoff accessed documents:\n\n"; $cutoffcnt = 0; foreach $key ( sort cnumerically_access ( keys %doccnt)) { printf "%7d times from %5d hosts for %s\n", $doccnt{$key},$dochstcnt{$key},$key; if($cutoffcnt++ > $cutoff){last;} } printf "\n\n$cutoff most active hosts:\n\n"; $cutoffcnt = 0; foreach $key ( sort cnumerically_host ( keys %hcount)) { last if $cutoffcnt++ >= $cutoff; printf "%7d times from %s\n", $hcount{$key},$key; last if $hcount{$key} <= 1; } $cutoffcnt = 0; printf "\n\n$cutoff most popular directories by volume:\n\n"; foreach $p ( sort cmp_directory_bytes keys %directory_bytes_hash) { printf "%9d %s\n", $directory_bytes_hash{$p}, $p; last if (++$cutoffcnt == $cutoff); } $cutoffcnt = 0; printf "\n\n$cutoff most popular clients by volume:\n\n"; foreach $p ( sort cmp_client_bytes keys %client_bytes_hash) { printf "%9d %s\n", $client_bytes_hash{$p}, $p; last if (++$cutoffcnt == $cutoff); } sub cnumerically_access { $doccnt{$b} <=> $doccnt{$a}; } sub cnumerically_host { $hcount{$b} <=> $hcount{$a}; } sub cmp_directory_bytes { $directory_bytes_hash{$b} <=> $directory_bytes_hash{$a}; } sub cmp_client_bytes { $client_bytes_hash{$b} <=> $client_bytes_hash{$a}; } sub directory_bytes { local($U,$S) = @_; local @C = split(/\//, $U); local ($u) = ''; local ($x) = $#C + 0; local ($c); return if ($S eq '-'); foreach $c (@C) { $u .= $c; $u .= '/' unless ($c eq $C[$x]); $directory_bytes_hash{$u} += $S; } }