Annotation of loncom/debugging_tools/login_count.pl, revision 1.7
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:
1.7 ! albertel 8: my $start_time=&UnixDate("Mar 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.7 ! albertel 29: if ($date > $start_time) {
! 30: push (@{$data{$date}},$user);
! 31: $machine{$machine}++;
! 32: }
1.1 albertel 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: }
1.2 albertel 38:
1.1 albertel 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}});
1.5 albertel 48: while ($counts[0] && $total_login >= $counts[0]) {
1.2 albertel 49: print("The $counts[0] ($total_login) login was ".
50: join(', ',@{$data{$key}})."\n");
51: shift(@counts);
52: }
53:
1.1 albertel 54: }
55: foreach my $key (sort(keys(%byday))) {
56: print("$key -> $byday{$key}\n");
57: }
58: print("total -> $total_login\n");
1.4 albertel 59: print("\nMachine Logins\n");
60: foreach my $key (sort(keys(%machine))) {
61: print("$key \t-> $machine{$key}\n");
62: }
1.1 albertel 63: }
64:
1.2 albertel 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>