[LON-CAPA-cvs] cvs: loncom /debugging_tools activity_to_accesscount.pl
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 14 Nov 2003 18:24:41 -0000
matthew Fri Nov 14 13:24:41 2003 EDT
Added files:
/loncom/debugging_tools activity_to_accesscount.pl
Log:
Activity log parser / access count taker. Sends some data to STDERR and
most to STDOUT.
Index: loncom/debugging_tools/activity_to_accesscount.pl
+++ loncom/debugging_tools/activity_to_accesscount.pl
#!/usr/bin/perl -w
#
use strict;
sub unescape {
my $str=shift;
$str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
return $str;
}
my %resourceaccess;
sub main {
my $file=$ARGV[0];
print STDERR "Using $file\n";
my $line;
open FILEID,'<'.$file;
my @allaccess;
print STDERR "Access by resource\n\n";
my $numlines = 0;
while ($line=<FILEID>) {
$numlines++;
if (int($numlines / 1000)*1000 == $numlines) {
if (int($numlines / 10000)*10000 == $numlines) {
print STDERR '*';
} else {
print STDERR '.';
}
if (int($numlines / 50000)*50000 == $numlines) {
print STDERR $/;
}
}
next if ($line eq '' || $line !~ /:/);
chomp($line);
my ($time,$machine,$what)=split(':',$line);
$what=&unescape($what);
my @accesses = split(/(\d{10}):/,$what);
shift(@accesses);
while (@accesses) {
my $date = shift(@accesses);
my $access = shift(@accesses);
next if (! defined($access) || $access eq '' ||
! defined($date) || $date eq '');
$access =~ s/(\&$|^:)//g;
my ($resource,$who,$domain,$post,@posts)=split(':',$access);
if (!$resource) {
next;
}
$resource = &unescape($resource);
if ($resource !~ m:/: || $resource =~ m:/prtspool/:) {
next;
}
if ($resource =~ /___\d+___/) {
(undef,$resource) = split(/___\d+___/,$resource);
}
next if ($resource =~ m:^/(res/adm|adm)/:);
$resource =~ s:^/?res/?::;
$resourceaccess{$resource}++;
}
}
print STDERR 'done.'.$/;
while (my ($resource,$count) = each(%resourceaccess)) {
print sprintf("%10.0f",$count).':'.$resource."\n";
}
}
main;