Diff for /loncom/cgi/clusterstatus.pl between versions 1.15 and 1.16

version 1.15, 2003/08/05 12:52:23 version 1.16, 2003/08/05 18:33:08
Line 7  $|=1; Line 7  $|=1;
   
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
   use strict;
   
 use LWP::UserAgent();  use LWP::UserAgent();
 use HTTP::Headers;  use HTTP::Headers;
Line 20  my %perlvar=(); Line 21  my %perlvar=();
   
 my $mode;  my $mode;
 my $concount=0;  my $concount=0;
   my $fromcache;
   
   my %domaindescription = ();
   my %domain_auth_def = ();
   my %domain_auth_arg_def = ();
   
   my %hostname=();
   my %hostip=();
   my %hostdom=();
   my %hostrole=();
   my %libserv=();
   
   my $maxusers=0;
   my $maxload=0;
   my $totalusers=0;
   
   my %FORM=();
   
   my $stat_total=0;
   my $stat_notyet=0;
   my $stat_fromcache=0;
   
 sub select_form {  sub select_form {
     my ($def,$name,%hash) = @_;      my ($def,$name,%hash) = @_;
Line 51  sub request { Line 73  sub request {
     $cachetime*=(0.5+rand);      $cachetime*=(0.5+rand);
     my $key=&key($local,$url);      my $key=&key($local,$url);
     my $reply='';      my $reply='';
       $stat_total++;
   # if fromcache flag is set, only return cached values
       if ($fromcache) {
    if ($FORM{$key.'_time'}) {
       return $FORM{$key};
       $stat_fromcache++;
    } else {
       return 'not_yet';
       $stat_notyet++;
    }
       }
   # normal mode, refresh when expired or not yet present
     if ($FORM{$key.'_time'}) {      if ($FORM{$key.'_time'}) {
  if ((time-$FORM{$key.'_time'})<$cachetime) {   if ((time-$FORM{$key.'_time'})<$cachetime) {
     $reply=$FORM{$key};      $reply=$FORM{$key};
     &hidden($key.'_time',$FORM{$key.'_time'});      &hidden($key.'_time',$FORM{$key.'_time'});
     &hidden($key.'_fromcache',1);      $stat_fromcache++;
  }   }
     }      }
     unless ($reply) {      unless ($reply) {
Line 97  sub connected { Line 131  sub connected {
 # but always do the first five.   # but always do the first five. 
 #  #
     unless ($FORM{&key($local,$url)}) {      unless ($FORM{&key($local,$url)}) {
  unless (($concount<=5) || (rand>0.95)) {    unless (($concount<=5) || (rand>0.95)) {
       $stat_total++;
       $stat_notyet++; 
     return 'not_yet';       return 'not_yet'; 
  } else {   } else {
     $concount++;      $concount++;
Line 260  sub doomedness { Line 296  sub doomedness {
     return sort { $alldoomed{$b} <=> $alldoomed{$a} } @allhosts;      return sort { $alldoomed{$b} <=> $alldoomed{$a} } @allhosts;
 }  }
   
 # ====================================================================== Status  sub resetvars {
 sub statuslist {     $maxusers=0;
     my ($local,$what)=@_;     $maxload=0;
     print      $totalusers=0;
 "<script>document.prgstat.progress.value='Testing $local ($hostname{$local}): $what';</script>\n";     $stat_total=0;
 }     $stat_notyet=0;
      $stat_fromcache=0;
 #  
 # Main program  
 #  
 # ========================================================= Get form parameters  
 my $buffer;  
   
 read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});  
 my @pairs=split(/&/,$buffer);  
 my $pair; my $name; my $value;  
 undef %FORM;  
 %FORM=();  
 foreach $pair (@pairs) {  
     ($name,$value) = split(/=/,$pair);  
     $value =~ tr/+/ /;  
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;  
     $FORM{$name}=$value;  
 }   
   
 $buffer=$ENV{'QUERY_STRING'};  
 @pairs=split(/&/,$buffer);  
 foreach $pair (@pairs) {  
     ($name,$value) = split(/=/,$pair);  
     $value =~ tr/+/ /;  
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;  
     $FORM{$name}=$value;  
 }   
   
 # ====================================================== Determine refresh rate  
   
 my $refresh=(($FORM{'refresh'}=~/^\d+$/)?$FORM{'refresh'}:120);  
 if ($refresh<30) { $refresh=30; }  
 my $starttime=time;  
   
 # ============================================================== Determine mode  
   
 my %modes=('trouble' => 'Trouble',  
    'users_doomed' => 'Doomed: Users',  
    'loncron_doomed' => 'Doomed: General (loncron)',  
    'mysql_doomed' => 'Doomed: Database (mysql)',  
    'notconnected_doomed' => 'Doomed: Connections',  
    'checkrpms_doomed' => 'Doomed: RPMs',  
    'load_doomed' => 'Doomed: Load',  
    'unresponsive_doomed' => 'Doomed: Status could not be determined',  
    'users' => 'User Report',  
    'load' => 'Load Report',  
    'connections' => 'Connections Matrix');  
   
 $mode=$FORM{'mode'};  
 unless ($modes{$mode}) { $mode='trouble'; }  
 # ================================================================ Send Headers  
 print "Content-type: text/html\n\n".  
     "<html><body bgcolor='#FFFFFF'>\n";  
 # -------------------- Read loncapa.conf (and by default, loncapa_apache.conf).  
 my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');  
 %perlvar=%{$perlvarref};  
 undef $perlvarref; # remove since sensitive and not needed  
 delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed  
 delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed  
   
 # ------------------------------------------------------------- Read hosts file     undef %host;
 {     %host=();
     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");  
   
     $total=0;  
     while (my $configline=<$config>) {  
        $configline=~s/#.*$//;  
        unless ($configline=~/\w/) { next; }   
        my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);  
        $hostname{$id}=$name;  
        $hostdom{$id}=$domain;  
        $hostrole{$id}=$role;  
        $hostip{$id}=$ip;  
        $total++;  
        if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {  
    $libserv{$id}=$name;  
        }  
     }  
 }  }
 # ------------------------------------------------------------ Read domain file  
 {  
     my $fh=IO::File->new($perlvar{'lonTabDir'}.'/domain.tab');  
     %domaindescription = ();  
     %domain_auth_def = ();  
     %domain_auth_arg_def = ();  
     if ($fh) {  
        while (<$fh>) {  
            next if (/^(\#|\s*$)/);  
            chomp;  
            my ($domain, $domain_description, $def_auth, $def_auth_arg)  
                = split(/:/,$_,4);  
            $domain_auth_def{$domain}=$def_auth;  
            $domain_auth_arg_def{$domain}=$def_auth_arg;  
            $domaindescription{$domain}=$domain_description;  
        }  
     }  
 }  
   
 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 />".  
 "</form>\n";;  
 print "<form name='status' method='post'>\n";  
 print 'Choose next report: '.&select_form($mode,'mode',%modes).'<hr />';  
 &hidden('refresh',$refresh);  
   
   sub mainloop {
       &resetvars();
 # ==================================================== Main Loop over all Hosts  # ==================================================== Main Loop over all Hosts
   
 my $maxusers=0;  foreach my $local (sort keys %hostname) {
 my $maxload=0;  
 my $totalusers=0;  
   
 foreach $local (sort keys %hostname) {  
     $host{$local.'_unresponsive_doomed'}=0;      $host{$local.'_unresponsive_doomed'}=0;
 # -- Check general status  # -- Check general status
     &statuslist($local,'General');      &statuslist($local,'General');
Line 472  foreach $local (sort keys %hostname) { Line 406  foreach $local (sort keys %hostname) {
     &statuslist($local,'Connections');      &statuslist($local,'Connections');
     $host{$local.'_notconnected'}='';      $host{$local.'_notconnected'}='';
     $host{$local.'_notconnected_doomed'}=0;      $host{$local.'_notconnected_doomed'}=0;
     foreach $remote (sort keys %hostname) {      foreach my $remote (sort keys %hostname) {
  my $status=&connected($local,$remote);   my $status=&connected($local,$remote);
  $connectionstatus{$local.'_TO_'.$remote}=$status;   $connectionstatus{$local.'_TO_'.$remote}=$status;
  unless (($status eq 'ok') || ($status eq 'not_yet')) {   unless (($status eq 'ok') || ($status eq 'not_yet')) {
Line 480  foreach $local (sort keys %hostname) { Line 414  foreach $local (sort keys %hostname) {
     $host{$local.'_notconnected_doomed'}++;      $host{$local.'_notconnected_doomed'}++;
  }   }
     }      }
 # =============================================================== End Mail Loop  # =============================================================== End Main Loop
   }
   
 }  }
 &statuslist('Done.');  
   sub reports {
 # ====================================================================== Output  # ====================================================================== Output
     if ($mode=~/\_doomed$/) {      if ($mode=~/\_doomed$/) {
 # Output by doomedness  # Output by doomedness
Line 538  foreach $local (sort keys %hostname) { Line 475  foreach $local (sort keys %hostname) {
     print "<h3>Total active user(s): $totalusers</h3>".       print "<h3>Total active user(s): $totalusers</h3>". 
        "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";         "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";
   
     foreach $local (sort keys %hostname) {      foreach my $local (sort keys %hostname) {
  if (defined($host{$local.'_users'})) {   if (defined($host{$local.'_users'})) {
     print       print 
 '<tr><th bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.$local.  '<tr><td bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.$local.
  '</font></th><td bgcolor="#DDDDBB">';   '</font><br /><font size="-2">'.
    $domaindescription{$hostdom{$local}}.
          '</font></td><td bgcolor="#DDDDBB">';
     &users($local);      &users($local);
     print       print 
       '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.        '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.
Line 561  foreach $local (sort keys %hostname) { Line 500  foreach $local (sort keys %hostname) {
     my $factor=50/$maxload;       my $factor=50/$maxload; 
     print      print
        "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";         "<table cellspacing='3' cellpadding='3' border='0' bgcolor='#225522'>";
     foreach $local (sort keys %hostname) {      foreach my $local (sort keys %hostname) {
  if (defined($host{$local.'_load_doomed'})) {   if (defined($host{$local.'_load_doomed'})) {
     print       print 
 '<tr><th bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.  '<tr><td bgcolor="#BBDDBB"><font face="arial" color="#225522" size="+1">'.
                         $local.                          $local.
  '</font></th><td bgcolor="#DDDDBB">';   '</font><br /><font size="-2">'.
    $domaindescription{$hostdom{$local}}.
          '</font></td><td bgcolor="#DDDDBB">';
     &server($local);      &server($local);
     print       print 
       '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.        '</td><td bgcolor="#DDDDBB"><font face="arial" color="#225522">'.
Line 581  foreach $local (sort keys %hostname) { Line 522  foreach $local (sort keys %hostname) {
  }   }
     } elsif ($mode eq 'trouble') {      } elsif ($mode eq 'trouble') {
  my $count=0;   my $count=0;
  foreach $local (sort keys %hostname) {   foreach my $local (sort keys %hostname) {
     my $trouble='';      my $trouble='';
     if ($host{$local.'_unresponsive_doomed'}>3) {      if ($host{$local.'_unresponsive_doomed'}>3) {
  $trouble='Does not respond to several queries.<br />';   $trouble='Does not respond to several queries.<br />';
Line 607  foreach $local (sort keys %hostname) { Line 548  foreach $local (sort keys %hostname) {
  }   }
  unless ($count) { print "No mayor trouble."; }   unless ($count) { print "No mayor trouble."; }
     }      }
   }
   
   # ====================================================================== Status
   sub statuslist {
       my ($local,$what)=@_;
       print 
   "<script>document.prgstat.progress.value='Testing $local ($hostname{$local}): $what';</script>\n";
   }
   
   # =============================================================================
   # =============================================================================
   # Main program
   #
   # ========================================================= Get form parameters
   my $buffer;
   
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   my @pairs=split(/&/,$buffer);
   my $pair; my $name; my $value;
   undef %FORM;
   %FORM=();
   foreach $pair (@pairs) {
       ($name,$value) = split(/=/,$pair);
       $value =~ tr/+/ /;
       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
       $FORM{$name}=$value;
   } 
   
   $buffer=$ENV{'QUERY_STRING'};
   @pairs=split(/&/,$buffer);
   foreach $pair (@pairs) {
       ($name,$value) = split(/=/,$pair);
       $value =~ tr/+/ /;
       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
       $FORM{$name}=$value;
   } 
   
   # ====================================================== Determine refresh rate
   
   my $refresh=(($FORM{'refresh'}=~/^\d+$/)?$FORM{'refresh'}:30);
   if ($refresh<30) { $refresh=30; }
   my $starttime=time;
   
   # ============================================================== Determine mode
   
   my %modes=('trouble' => 'Trouble',
      'users_doomed' => 'Doomed: Users',
      'loncron_doomed' => 'Doomed: General (loncron)',
      'mysql_doomed' => 'Doomed: Database (mysql)',
      'notconnected_doomed' => 'Doomed: Connections',
      'checkrpms_doomed' => 'Doomed: RPMs',
      'load_doomed' => 'Doomed: Load',
      'unresponsive_doomed' => 'Doomed: Status could not be determined',
      'users' => 'User Report',
      'load' => 'Load Report',
      'connections' => 'Connections Matrix');
   
   $mode=$FORM{'mode'};
   unless ($modes{$mode}) { $mode='trouble'; }
   # ================================================================ Send Headers
   print "Content-type: text/html\n\n".
       "<html><body bgcolor='#FFFFFF'>\n";
   # -------------------- Read loncapa.conf (and by default, loncapa_apache.conf).
   my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
   %perlvar=%{$perlvarref};
   undef $perlvarref; # remove since sensitive and not needed
   delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
   delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
   
   # ------------------------------------------------------------- Read hosts file
   {
       my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
   
       while (my $configline=<$config>) {
          $configline=~s/#.*$//;
          unless ($configline=~/\w/) { next; } 
          my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
          $hostname{$id}=$name;
          $hostdom{$id}=$domain;
          $hostrole{$id}=$role;
          $hostip{$id}=$ip;
          if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
      $libserv{$id}=$name;
          }
       }
   }
   # ------------------------------------------------------------ Read domain file
   {
       my $fh=IO::File->new($perlvar{'lonTabDir'}.'/domain.tab');
       if ($fh) {
          while (<$fh>) {
              next if (/^(\#|\s*$)/);
              chomp;
              my ($domain, $domain_description, $def_auth, $def_auth_arg)
                  = split(/:/,$_,4);
              $domain_auth_def{$domain}=$def_auth;
              $domain_auth_arg_def{$domain}=$def_auth_arg;
              $domaindescription{$domain}=$domain_description;
          }
       }
   }
   
   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 />".
   "</form>\n";;
   print "<form name='status' method='post'>\n";
   print 'Choose next report: '.&select_form($mode,'mode',%modes).'<hr />';
   &hidden('refresh',$refresh);
   
       if (!$FORM{'runonetime'}) {
    print 
      "<h3>Gathering initial cluster data</h3>This may take some time ...<br />";
    $fromcache=0;
    &mainloop();
    &statuslist('Done initial run.');
    &reports();
       } else {
    $fromcache=1;
    &mainloop();
    &statuslist('Done gathering cached data');
    &reports();
    $fromcache=0;
    &mainloop();
       }
       &hidden('runonetime',1);
   print '<tt><br />Total number of queries: '.$stat_total.
             '<br />Percent complete: '.
     int(($stat_total-$stat_notyet)/$stat_total*100.).
     '<br />Percent from cache: '.
             int($stat_fromcache/$stat_total*100.).'</tt>';
   
 # ============================================================== Close, refresh  # ============================================================== Close, refresh
 print "</form><script>";  print "</form><script>";
 $runtime=time-$starttime;  my $runtime=time-$starttime;
 if (($refresh-$runtime)<30) {  if (($refresh-$runtime)<0) {
     print "setTimeout('document.status.submit()',30000);\n".      print "document.status.submit();";
           "document.prgstat.progress.value='Will automatically refresh.'";  
 } else {  } else {
     $refreshtime=int(1000*($refresh-$runtime));      my $refreshtime=int(1000*($refresh-$runtime));
     print "setTimeout('document.status.submit()',$refreshtime);\n".      print "setTimeout('document.status.submit()',$refreshtime);\n".
           "document.prgstat.progress.value='Will automatically refresh ($refresh secs refresh cycle)'";            "document.prgstat.progress.value='Will automatically refresh ($refresh secs refresh cycle)'";
 }  }

Removed from v.1.15  
changed lines
  Added in v.1.16


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