--- stat/calc.pl 2002/03/07 12:18:51 1.1 +++ stat/calc.pl 2002/03/07 17:10:47 1.2 @@ -1,17 +1,42 @@ #!/usr/bin/perl -w +use strict; + +my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); + +my $mon_nr=1; +my %month2nr; +foreach my $mon (@months) { + $month2nr{$mon}=sprintf("%02d",$mon_nr); + $mon_nr++; +} + my %count; +my %get; +my %post; while(<>) { chomp; - if (m,\[(\d+/\w+/\d{4}:)(\d\d):(\d\d:)\d\d\s+\S+\]\s+"(\w+)\s+,) { - my ($date,$hh,$mm,$method) = ($1,$2,$3,$4); - $count{"$date$hh"}++; + if (m,\[(\d+)/(\w+)/(\d{4}):(\d\d):(\d\d):\d\d\s+\S+\]\s+"([^"]+)"\s+,) { + my ($dd,$mmm,$yyyy,$hh,$mm,$method) = ($1,$2,$3,$4,$5,$6); + die "can't convert '$mmm' to number!" if (! defined($month2nr{$mmm})); +# my $date="$yyyy-".$month2nr{$mmm}."-$dd $hh"; + my $date="$yyyy-".$month2nr{$mmm}."-$dd 00"; + if ($method =~ m/nn\.cgi/) { + $count{$date}++; + $get{$date}=0 if (! defined($get{$date})); + $post{$date}=0 if (! defined($post{$date})); + if ($method =~ m/get/i) { + $get{$date}++; + } else { + $post{$date}++; + } + } } else { print STDERR "line '$_' skipped!\n"; } } foreach (keys %count) { - print "$_\t$count{$_}\n"; + print "$_\t$count{$_}\t$get{$_}\t$post{$_}\n"; }