Annotation of loncom/debugging_tools/login_count.pl, revision 1.8
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.8 ! albertel 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.8 ! albertel 10: my @ignored_users=('^itds\d+$');
1.2 albertel 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];
1.8 ! albertel 26: foreach my $expr (@ignored_users) {
! 27: if ($user=~/$expr/) { print("\nignoring $user\n"); return; }
! 28: }
1.1 albertel 29: while (my $line=<FILE>) {
30: if ($line !~ /Login/) { next; }
1.4 albertel 31: my ($date,$machine)=split(':',$line,3);
1.7 albertel 32: if ($date > $start_time) {
33: push (@{$data{$date}},$user);
34: $machine{$machine}++;
35: }
1.1 albertel 36: }
37: if ($numusers%100 == 0) {
38: print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
39: }
40: }
1.2 albertel 41:
1.1 albertel 42: sub print_data {
43: my $total_login=0;
44: my %byday;
45: print("\n");
46: foreach my $key (sort(keys(%data))) {
47: #print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
48: $total_login+=scalar(@{$data{$key}});
49: my $day=strftime('%F',localtime($key));
50: $byday{$day}+=scalar(@{$data{$key}});
1.5 albertel 51: while ($counts[0] && $total_login >= $counts[0]) {
1.2 albertel 52: print("The $counts[0] ($total_login) login was ".
53: join(', ',@{$data{$key}})."\n");
54: shift(@counts);
55: }
56:
1.1 albertel 57: }
58: foreach my $key (sort(keys(%byday))) {
59: print("$key -> $byday{$key}\n");
60: }
61: print("total -> $total_login\n");
1.4 albertel 62: print("\nMachine Logins\n");
63: foreach my $key (sort(keys(%machine))) {
64: print("$key \t-> $machine{$key}\n");
65: }
1.1 albertel 66: }
67:
1.2 albertel 68: $|=1;
69: sub main {
70: my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
71: find(
72: {
73: # preprocess => \&only_user_activitylog_files,
74: # wanted => \&print_filename,
75: # wanted => \&log_metadata,
76: wanted => \&process_activitylog_file,
77: },
78: $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
79: &print_data();
80: }
81: &main();
82:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>