[LON-CAPA-cvs] cvs: loncom /cgi clusterstatus.pl

www lon-capa-cvs@mail.lon-capa.org
Thu, 31 Jul 2003 19:18:16 -0000


This is a MIME encoded message

--www1059679096
Content-Type: text/plain

www		Thu Jul 31 15:18:16 2003 EDT

  Modified files:              
    /loncom/cgi	clusterstatus.pl 
  Log:
  Bug #797: seems to work.
  
  
--www1059679096
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20030731151816.txt"

Index: loncom/cgi/clusterstatus.pl
diff -u loncom/cgi/clusterstatus.pl:1.10 loncom/cgi/clusterstatus.pl:1.11
--- loncom/cgi/clusterstatus.pl:1.10	Thu Jul 31 12:07:47 2003
+++ loncom/cgi/clusterstatus.pl	Thu Jul 31 15:18:16 2003
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Cluster Status
 #
-# $Id: clusterstatus.pl,v 1.10 2003/07/31 16:07:47 www Exp $
+# $Id: clusterstatus.pl,v 1.11 2003/07/31 19:18:16 www Exp $
 
 use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;
@@ -169,11 +169,23 @@
     print &otherwindow($local,'/server-status','Server Status');
 }
 
+# ========================================================= Produce a green bar
+sub bar {
+    my $parm=shift;
+    my $number=int($parm+0.5);
+    print "<table><tr><td bgcolor='#225522'><font color='#225522'>";
+    for (my $i=0;$i<$number;$i++) {
+	print "+";
+    }
+    print "</font></table>";
+}
+
 # ========================================================== Show server status
 
 sub serverstatus {
-    my $local=shift;
+    my ($local,$trouble)=@_;
     print (<<ENDHEADER);
+<a name="$local" />
 <table width="100%" bgcolor="#225522" cellspacing="2" cellpadding="2" border="0">
 <tr><td bgcolor="#BBDDBB"><font color="#225522" face="arial"><b>
 $local $hostdom{$local}</b> <tt>($hostname{$local}; $hostrole{$local})</tt>
@@ -182,7 +194,11 @@
 ENDHEADER
     &login($local);&server($local);&users($local);&versions($local);
     &loncron($local);&lond($local);&lonc($local);&runloncron($local);
-    print "</font></td></tr><tr><td bgcolor='#BBBBBB'>";
+    print "</font></td></tr>";
+    if ($trouble) {
+	print ("<tr><td bgcolor='#DDBBBB'><font color='#552222' size='+2'>$trouble</font></td></tr>");
+    }
+    print "<tr><td bgcolor='#BBBBBB'>";
 # load
     if (($host{$local.'_load_doomed'}>0.5) || ($mode eq 'load_doomed')) {
 	print "<br />Load: ".$host{$local.'_load'}
@@ -200,6 +216,19 @@
     if ($host{$local.'_mysql'}) {
 	print "<br />MySQL Database: ".$host{$local.'_mysql'}
     }
+# connections
+    if ($host{$local.'_notconnected'}) {
+	print "<br />Not connected: ";
+	foreach (split(/ /,$host{$local.'_notconnected'})) {
+	    if ($_) {
+		print " <a href='#$_'>$_</a>";
+	    }
+	}
+    }
+# errors
+    if ($host{$local.'_errors'}) {
+	print "<br />loncron errors: ".$host{$local.'_errors'};
+    }
     print "</td></tr></table><br />";
 }
 
@@ -256,7 +285,7 @@
 
 # ====================================================== Determine refresh rate
 
-my $refresh=(($FORM{'refresh'}=~/^\d+$/)?$FORM{'refresh'}:60);
+my $refresh=(($FORM{'refresh'}=~/^\d+$/)?$FORM{'refresh'}:120);
 if ($refresh<30) { $refresh=30; }
 my $starttime=time;
 
@@ -271,6 +300,7 @@
 	   'load_doomed' => 'Doomed: Load',
 	   'unresponsive_doomed' => 'Doomed: Status could not be determined',
 	   'users' => 'User Report',
+	   'load' => 'Load Report',
 	   'connections' => 'Connections Matrix');
 
 $mode=$FORM{'mode'};
@@ -323,7 +353,6 @@
     }
 }
 
-
 print "<img src='/adm/lonIcons/lonlogos.gif' align='right' /><h1>LON-CAPA Cluster Status ".localtime()."</h1>";
 print "<form name='prgstat'>\n".
 "<input type='text' name='progress' value='Starting ...' size='100' /><br />".
@@ -334,6 +363,10 @@
 
 # ==================================================== Main Loop over all Hosts
 
+my $maxusers=0;
+my $maxload=0;
+my $totalusers=0;
+
 foreach $local (sort keys %hostname) {
     $host{$local.'_unresponsive_doomed'}=0;
 # -- Check general status
@@ -347,6 +380,10 @@
 	    $host{$local.'_loncron'}='Stale.';
 	    $host{$local.'_unresponsive_doomed'}++;
 	} else {
+	    $host{$local.'_loncron_doomed'}=$loncron{'notices'}
+	                                 +4*$loncron{'warnings'}
+	                               +100*$loncron{'errors'};
+	    $host{$local.'_errors'}=$loncron{'errors'};
 	}
     }
 # -- Check user status
@@ -358,8 +395,16 @@
     } else {
 	$host{$local.'_users_doomed'}=$userstatus{'Active'};
 	$host{$local.'_users'}=$userstatus{'Active'};
+	unless ($host{$local.'_users'}) { $host{$local.'_users'}=0; }
+	if ($host{$local.'_users'}>$maxusers) { 
+	    $maxusers=$host{$local.'_users'};
+	}
+	$totalusers+=$host{$local.'_users'};
 	my ($sload,$mload,$lload)=split(/ /,$userstatus{'loadavg'});
 	$host{$local.'_load_doomed'}=$mload;
+	if ($mload>$maxload) { 
+	    $maxload=$mload;
+	}
 	$host{$local.'_load'}=$userstatus{'loadavg'};
     }
 # -- Check mysql status
@@ -428,17 +473,14 @@
 	print 
        "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>".
        "<tr><td bgcolor='#225522'>&nbsp;</td>";
-	foreach (sort keys %hostname) {
-	    my $remote=$_;
+	foreach my $remote (sort keys %hostname) {
 	    print '<th bgcolor="#DDDDBB">'.$remote.'</th>';
 	}
 	print "</tr>\n";
 # connection matrix
-	foreach (sort keys %hostname) {
-	    my $local=$_;
+	foreach my $local (sort keys %hostname) {
 	    print '<tr><th bgcolor="#DDDDBB">'.$local.'</th>';
-	    foreach (sort keys %hostname) {
-		my $remote=$_;
+	    foreach my $remote (sort keys %hostname) {
 		if ($connectionstatus{$local.'_TO_'.$remote} eq 'not_yet') {
 		    print '<td bgcolor="#FFFFFF">&nbsp;</td>';
 		} elsif ($connectionstatus{$local.'_TO_'.$remote} eq 'ok') {
@@ -454,8 +496,80 @@
 	    }
 	    print "</tr>\n";
 	}
+	print "</table>";
+    } elsif ($mode eq 'users') {
+# Users
+	if ($maxusers) {
+	    my $factor=50/$maxusers;
+	    print "<h3>Total active user(s): $totalusers</h3>". 
+       "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";
+
+	    foreach $local (sort keys %hostname) {
+		if (defined($host{$local.'_users'})) {
+		    print 
+'<tr><th bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.$local.
+			'</font></th><td bgcolor="#DDDDBB">';
+		    &users();
+		    print 
+	      '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.
+	      $host{$local.'_users'}.'</font></td><td bgcolor="#DDDDBB"';
+		    &bar($factor*$host{$local.'_users'});
+		    print "</td></tr>\n";
+		}
+	    }
+	    print "</table>";
+	} else {
+	    print "No active users logged in.";
+	}
+    } elsif ($mode eq 'load') {
+# Load
+	if ($maxload) {
+	    my $factor=50/$maxload; 
+	    print
+       "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";
+	    foreach $local (sort keys %hostname) {
+		if (defined($host{$local.'_load_doomed'})) {
+		    print 
+'<tr><th bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.
+                        $local.
+			'</font></th><td bgcolor="#DDDDBB">';
+		    &server();
+		    print 
+	      '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.
+	      $host{$local.'_load_doomed'}.'</font></td><td bgcolor="#DDDDBB"';
+		    &bar($factor*$host{$local.'_load_doomed'});
+		    print "</td></tr>\n";
+		}
+	    }
+	    print "</table>";
+	} else {
+	    print "No workload.";
+	}
+    } elsif ($mode eq 'trouble') {
+	my $count=0;
+	foreach $local (sort keys %hostname) {
+	    my $trouble='';
+	    if ($host{$local.'_errors'}) {
+		$trouble='Has loncron errors.<br />';
+	    } elsif ($host{$local.'_loncron_doomed'}>600) {
+		$trouble='High loncron count.<br />';
+	    }
+	    if ($host{$local.'_load_doomed'}>5) {
+		$trouble='High load.<br />';
+	    }
+	    if ($host{$local.'_users_doomed'}>200) {
+		$trouble='High user volume.<br />';
+	    }
+	    if ($host{$local.'_mysql_doomed'}>1) {
+		$trouble='MySQL database apparently offline.<br />';
+	    }
+	    if ($host{$local.'_checkrpms_doomed'}>100) {
+		$trouble='RPMs outdated.<br />';
+	    }
+	    if ($trouble) { $count++; &serverstatus($local,$trouble); }
+	}
+	unless ($count) { print "No mayor trouble."; }
     }
-    print "</table>";
 # ============================================================== Close, refresh
 print "</form><script>";
 $runtime=time-$starttime;
@@ -463,7 +577,8 @@
     print 'document.status.submit();';
 } else {
     $refreshtime=int(1000*($refresh-$runtime));
-    print "setTimeout('document.status.submit()',$refreshtime);";
+    print "setTimeout('document.status.submit()',$refreshtime);\n".
+          "document.prgstat.progress.value='Will automatically refresh ($refresh secs refresh cycle)'";
 }
 print "</script></body></html>";
 exit 0;

--www1059679096--