Annotation of loncom/debugging_tools/login_count.pl, revision 1.6

1.2       albertel    1: use strict;
1.1       albertel    2: use File::Find;
                      3: use POSIX qw(strftime);
                      4: use lib '/home/httpd/lib/perl/';
                      5: use LONCAPA::Configuration;
                      6: use Date::Manip;
1.2       albertel    7: 
                      8: my $start_time=&UnixDate("Aug 30th 00:00:00 2004","%s");
1.6     ! albertel    9: my @counts=('1','10','100','1000','10000','100000','250000','1000000');
1.2       albertel   10: 
                     11: 
1.1       albertel   12: sub only_user_activitylog_files {
                     13:     print (join("\n",@_));
                     14:     return 1;
                     15: }
                     16: 
                     17: my %data;
                     18: my $numusers;
1.4       albertel   19: my %machine;
1.1       albertel   20: sub process_activitylog_file {
                     21:     if ($File::Find::dir=~m|/\d/\d/\d/|) { return; }
                     22:     if ($_ ne 'activity.log') {	return; }
                     23:     open(FILE,"<$File::Find::name");
                     24:     $numusers++;
                     25:     my $user=(split('/',$File::Find::dir))[-1];
                     26:     while (my $line=<FILE>) {
                     27: 	if ($line !~ /Login/) { next; }
1.4       albertel   28: 	my ($date,$machine)=split(':',$line,3);
1.3       albertel   29: 	if ($date > $start_time) { push (@{$data{$date}},$user);	}
1.4       albertel   30: 	$machine{$machine}++;
1.1       albertel   31:     }
                     32:     if ($numusers%100 == 0) {
                     33: 	print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
                     34:     }
                     35: }
1.2       albertel   36: 
1.1       albertel   37: sub print_data {
                     38:     my $total_login=0;
                     39:     my %byday;
                     40:     print("\n");
                     41:     foreach my $key (sort(keys(%data))) {
                     42: 	#print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
                     43: 	$total_login+=scalar(@{$data{$key}});
                     44: 	my $day=strftime('%F',localtime($key));
                     45: 	$byday{$day}+=scalar(@{$data{$key}});
1.5       albertel   46: 	while ($counts[0] && $total_login >= $counts[0]) {
1.2       albertel   47: 	    print("The $counts[0] ($total_login) login was ".
                     48: 		  join(', ',@{$data{$key}})."\n");
                     49:             shift(@counts);
                     50:         }
                     51: 
1.1       albertel   52:     }
                     53:     foreach my $key (sort(keys(%byday))) {
                     54:     	print("$key -> $byday{$key}\n");
                     55:     }
                     56:     print("total -> $total_login\n");
1.4       albertel   57:     print("\nMachine Logins\n");
                     58:     foreach my $key (sort(keys(%machine))) {
                     59: 	print("$key \t-> $machine{$key}\n");
                     60:     }
1.1       albertel   61: }
                     62: 
1.2       albertel   63: $|=1;
                     64: sub main {
                     65:     my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
                     66:     find(
                     67:          {
                     68: #          preprocess => \&only_user_activitylog_files,
                     69: #          wanted     => \&print_filename,
                     70: #          wanted     => \&log_metadata,
                     71: 	     wanted     => \&process_activitylog_file,
                     72: 	 }, 
                     73:          $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
                     74:     &print_data();
                     75: }
                     76: &main();
                     77: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>