head 1.6; access; symbols; locks; strict; comment @# @; 1.6 date 2003.12.03.16.38.25; author wessels; state Exp; branches; next 1.5; 1.5 date 2000.11.20.15.27.06; author wessels; state Exp; branches; next 1.4; 1.4 date 99.09.25.06.23.12; author wessels; state Exp; branches; next 1.3; 1.3 date 99.09.25.04.56.07; author wessels; state Exp; branches; next 1.2; 1.2 date 99.09.25.04.55.36; author wessels; state Exp; branches; next 1.1; 1.1 date 99.09.25.04.55.11; author wessels; state Exp; branches; next ; desc @@ 1.6 log @cleanup perl @ text @#!/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; } } @ 1.5 log @added top directories/clients by volume @ text @d10 2 @ 1.4 log @*** empty log message *** @ text @d1 2 a2 2 #!/usr/bin/perl # $Id: httpsum.pl,v 1.3 1999/09/25 04:56:07 wessels Exp wessels $ d11 6 a16 1 ($from,$t,$t,$time,$offset,$cmd,$what,@@r)=split; d22 2 d29 1 a29 1 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($curtime); d32 1 d55 14 d71 16 @ 1.3 log @*** empty log message *** @ text @d2 1 a2 1 # $Id$ d8 1 a8 1 chop( $hostname = `hostname` ); d37 1 a37 1 printf "\n\nAt most $cutoff most active hosts:\n\n"; @ 1.2 log @*** empty log message *** @ text @d2 1 @ 1.1 log @Initial revision @ text @d5 1 a5 1 $curtime=time(); # get current time stamp d7 1 a7 1 $hostname = shift || die "usage: $0 servername\n"; d29 2 a30 1 foreach $key ( sort cnumerically ( keys %doccnt)) { d36 12 a47 1 sub cnumerically { $doccnt{$b} <=> $doccnt{$a} ;} @