File:  [LON-CAPA] / loncom / debugging_tools / login_count.pl
Revision 1.7: download - view: text, annotated - select for diffs
Wed Mar 30 18:04:53 2005 UTC (19 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- err, oops

    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("Mar 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) {
   30: 	    push (@{$data{$date}},$user);
   31: 	    $machine{$machine}++;
   32: 	}
   33:     }
   34:     if ($numusers%100 == 0) {
   35: 	print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
   36:     }
   37: }
   38: 
   39: sub print_data {
   40:     my $total_login=0;
   41:     my %byday;
   42:     print("\n");
   43:     foreach my $key (sort(keys(%data))) {
   44: 	#print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
   45: 	$total_login+=scalar(@{$data{$key}});
   46: 	my $day=strftime('%F',localtime($key));
   47: 	$byday{$day}+=scalar(@{$data{$key}});
   48: 	while ($counts[0] && $total_login >= $counts[0]) {
   49: 	    print("The $counts[0] ($total_login) login was ".
   50: 		  join(', ',@{$data{$key}})."\n");
   51:             shift(@counts);
   52:         }
   53: 
   54:     }
   55:     foreach my $key (sort(keys(%byday))) {
   56:     	print("$key -> $byday{$key}\n");
   57:     }
   58:     print("total -> $total_login\n");
   59:     print("\nMachine Logins\n");
   60:     foreach my $key (sort(keys(%machine))) {
   61: 	print("$key \t-> $machine{$key}\n");
   62:     }
   63: }
   64: 
   65: $|=1;
   66: sub main {
   67:     my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
   68:     find(
   69:          {
   70: #          preprocess => \&only_user_activitylog_files,
   71: #          wanted     => \&print_filename,
   72: #          wanted     => \&log_metadata,
   73: 	     wanted     => \&process_activitylog_file,
   74: 	 }, 
   75:          $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
   76:     &print_data();
   77: }
   78: &main();
   79: 

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