#!/usr/local/bin/perl use Time::Local; require 'getopts.pl'; ### ### default values ### $ath = 64; $tth = $ath; $tunit = 3600; # 1 hour $sth = 8; $sunit = 1024; # 1 K $pth = $ath; sub usage { print < 0, "feb" => 1, "mar" => 2, "apr" => 3, "may" => 4, "jun" => 5, "jul" => 6, "aug" => 7, "sep" => 8, "oct" => 9, "nov" =>10, "dec" =>11, ); sub report_normal { my($tempalist) = @_; my($n, $v); while( ($n, $v) = each %{ $tempalist } ) { print "\t\t$n $v\n"; } } sub report_timeband { my($tempalist) = @_; my(%alist) = %{ $tempalist } ; my(@tlist) = sort {$a<=>$b} keys %alist; my($n, $v); my($t0, $t1, $diff, $be, $en, $sum); my(%band); if(0) { $sum = 0; while( ($n, $v) = each %alist ) { print "\t\t$n $v\n"; $sum += $v; } print "\t\ttmp-sum $sum\n"; } @nlist = keys %alist; if($#nlist<=$tth) { &report_normal( $tempalist ); return 0; } while($#tlist>-1) { $t0 = shift @tlist; $be = $t0; $en = $t0; $sum = $alist{$t0}; # print "\tt0 $t0 $alist{$t0}\n"; while(1) { $t1 = shift @tlist; if($t1 eq '') { last; } $diff= $t1 - $en; # print "\t t1 $t1 $alist{$t1} diff $diff\n"; if($diff<=$tunit) { $en = $t1; $sum += $alist{$t1}; } else { unshift @tlist, $t1; last; } } $band{$be ."-". ($en+$tunit-1) } = $sum; #print "\t\t band{$be-$en}=$sum\n"; } $sum = 0; foreach $n (sort {$a<=>$b} keys %band) { print "\t\t$n $band{$n}\n"; $sum += $band{$n}; } # print "\t\tsum $sum\n"; undef %band; } sub report_sizeband { my($tempalist) = @_; my(%alist) = %{ $tempalist } ; my(%nalist); my($n, $be, $en, $v); my(@nlist); @nlist = keys %alist; if($#nlist<=$sth) { &report_normal( $tempalist ); return 0; } foreach $n (@nlist) { $nalist{ int($n/$sunit) } += $alist{$n}; } foreach $n (sort {$a<=>$b} keys %nalist) { $be = $n*$sunit; $en = $be+$sunit -1; print "\t\t$be-$en $nalist{$n}\n"; } } while(<>) { if(/^(\S+)\s+(\S+)\s+(\S+)\s+\[(\S+)\s+(\+?-?\d+)\]\s+"(\w+)\s+(\S+)\s+(HTTP\/\d+\.\d+)"\s+(\d+)\s+(\d+)$/) { $peer = $1; $xdate = $4; $method = $6; $uri = $7; $xver = $8; $rcode = $9; $size = $10; # typical value # 29/Dec/2000:00:00:03 # $xdate =~ /(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)/; $xda = $1; $xxmo = $2; $xye = $3; $xho = $4; $xmi = $5; $xse = $6; $xxmo =~ tr/A-Z/a-z/; $xmo = $monthconv{$xxmo}; $xye -= 1900; $t = timelocal($xse, $xmi, $xho, $xda, $xmo, $xye); $ucount{$uri}++; $count{$uri}{"time"}{int($t/$tunit)*$tunit}++; $count{$uri}{"peer"}{$peer}++; $count{$uri}{"method"}{$method}++; $count{$uri}{"rcode"}{$rcode}++; $count{$uri}{"size"}{$size}++; } } foreach $name (keys %count) { print "$name\n"; print "\tcount\n\t\t$ucount{$name}\n"; while(($a, $av) = each %{ $count{$name} } ) { print "\t$a\n"; if($a eq 'time') { &report_timeband( $av ); } elsif($a eq 'size') { &report_sizeband( $av ); } elsif($a eq 'peer' && $ucount{$name} > $pth ) { print "\t\t-\n"; } else { &report_normal( $av ); } } }