[LON-CAPA-cvs] cvs: loncom / lond

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 08 May 2003 21:25:31 -0000


albertel		Thu May  8 17:25:31 2003 EDT

  Modified files:              
    /loncom	lond 
  Log:
  - user load calulation added BUG#958
  
  
Index: loncom/lond
diff -u loncom/lond:1.126 loncom/lond:1.127
--- loncom/lond:1.126	Tue May  6 17:36:42 2003
+++ loncom/lond	Thu May  8 17:25:31 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.126 2003/05/06 21:36:42 albertel Exp $
+# $Id: lond,v 1.127 2003/05/08 21:25:31 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,7 +73,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.126 $'; #' stupid emacs
+my $VERSION='$Revision: 1.127 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -665,8 +665,12 @@
                           $loadavg=<$loadfile>;
                        }
                        $loadavg =~ s/\s.*//g;
-                       my $loadpercent=100*$loadavg/$perlvar{'lonLoadLim'};
+		       my $loadpercent=100*$loadavg/$perlvar{'lonLoadLim'};
 		       print $client "$loadpercent\n";
+# -------------------------------------------------------------------- userload
+		   } elsif ($userinput =~ /^userload/) {
+		       my $userloadpercent=&userload();
+		       print $client "$userloadpercent\n";
 # ----------------------------------------------------------------- currentauth
 		   } elsif ($userinput =~ /^currentauth/) {
 		     if ($wasenc==1) {
@@ -2065,6 +2069,27 @@
     my ($userinput)=@_;
     $remoteVERSION=(split(/:/,$userinput))[1];
     return "version:$VERSION";
+}
+
+sub userload {
+    my $numusers=0;
+    {
+	opendir(LONIDS,$perlvar{'lonIDsDir'});
+	my $filename;
+	my $curtime=time;
+	while ($filename=readdir(LONIDS)) {
+	    if ($filename eq '.' || $filename eq '..') {next;}
+	    my ($atime)=(stat($perlvar{'lonIDsDir'}.'/'.$filename))[8];
+	    if ($curtime-$atime < 3600) { $num_users++; }
+	}
+	closedir(LONIDS);
+    }
+    my $userloadpercent=0;
+    my $maxuserload=$perlvar{'lonUserLoadLim'};
+    if ($maxuserload) {
+	$userloadpercent=100*$num_users/$maxuserload;
+    }
+    return $userloadpercent;
 }
 
 # ----------------------------------- POD (plain old documentation, CPAN style)