File:  [LON-CAPA] / loncom / debugging_tools / login_count.pl
Revision 1.6: download - view: text, annotated - select for diffs
Wed Mar 30 17:41:30 2005 UTC (19 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- add million in by default

    1: use strict;
    2: use File::Find;
    3: use POSIX qw(strftime);
    4: use lib '/home/httpd/lib/perl/';
    5: use LONCAPA::Configuration;
    6: use Date::Manip;
    7: 
    8: my $start_time=&UnixDate("Aug 30th 00:00:00 2004","%s");
    9: my @counts=('1','10','100','1000','10000','100000','250000','1000000');
   10: 
   11: 
   12: sub only_user_activitylog_files {
   13:     print (join("\n",@_));
   14:     return 1;
   15: }
   16: 
   17: my %data;
   18: my $numusers;
   19: my %machine;
   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; }
   28: 	my ($date,$machine)=split(':',$line,3);
   29: 	if ($date > $start_time) { push (@{$data{$date}},$user);	}
   30: 	$machine{$machine}++;
   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: }
   36: 
   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}});
   46: 	while ($counts[0] && $total_login >= $counts[0]) {
   47: 	    print("The $counts[0] ($total_login) login was ".
   48: 		  join(', ',@{$data{$key}})."\n");
   49:             shift(@counts);
   50:         }
   51: 
   52:     }
   53:     foreach my $key (sort(keys(%byday))) {
   54:     	print("$key -> $byday{$key}\n");
   55:     }
   56:     print("total -> $total_login\n");
   57:     print("\nMachine Logins\n");
   58:     foreach my $key (sort(keys(%machine))) {
   59: 	print("$key \t-> $machine{$key}\n");
   60:     }
   61: }
   62: 
   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>