File:  [LON-CAPA] / loncom / loncron
Revision 1.26: download - view: text, annotated - select for diffs
Sat May 11 21:18:14 2002 UTC (21 years, 11 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
using LONCAPA::Configuration::read_conf
BUG 129

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network
    4: # Housekeeping program, started by cron
    5: #
    6: # (TCP networking package
    7: # 6/1/99,6/2,6/10,6/11,6/12,6/14,6/26,6/28,6/29,6/30,
    8: # 7/1,7/2,7/9,7/10,7/12 Gerd Kortemeyer)
    9: #
   10: # 7/14,7/15,7/19,7/21,7/22,11/18,
   11: # 2/8 Gerd Kortemeyer
   12: # 12/6/2000,12/8 Scott Harrison
   13: # 12/23 Gerd Kortemeyer
   14: # YEAR=2001
   15: # 1/10/2001, 2/12/, 2/26, 3/15, 04/11, 04/21,8/27 Scott Harrison
   16: # 09/04,09/06,11/26 Gerd Kortemeyer
   17: # YEAR=2002
   18: # 5/11/2002 Scott Harrison
   19: 
   20: $|=1;
   21: 
   22: use lib '/home/httpd/lib/perl/';
   23: use LONCAPA::Configuration;
   24: 
   25: use IO::File;
   26: use IO::Socket;
   27: 
   28: # -------------------------------------------------- Non-critical communication
   29: sub reply {
   30:     my ($cmd,$server)=@_;
   31:     my $peerfile="$perlvar{'lonSockDir'}/$server";
   32:     my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",
   33:                                      Type    => SOCK_STREAM,
   34:                                      Timeout => 10)
   35:        or return "con_lost";
   36:     print $client "$cmd\n";
   37:     my $answer=<$client>;
   38:     chomp($answer);
   39:     if (!$answer) { $answer="con_lost"; }
   40:     return $answer;
   41: }
   42: 
   43: # --------------------------------------------------------- Output error status
   44: 
   45: sub errout {
   46:    my $fh=shift;
   47:    print $fh (<<ENDERROUT);
   48:      <p><table border=2 bgcolor="#CCCCCC">
   49:      <tr><td>Notices</td><td>$notices</td></tr>
   50:      <tr><td>Warnings</td><td>$warnings</td></tr>
   51:      <tr><td>Errors</td><td>$errors</td></tr>
   52:      </table><p><a href="#top">Top</a><p>
   53: ENDERROUT
   54: }
   55: 
   56: # ================================================================ Main Program
   57: 
   58: # ------------------------------------------- Read access.conf and loncapa.conf
   59: my $perlvarref=LONCAPA::Configuration::read_conf('access.conf','loncapa.conf');
   60: my %perlvar=%{$perlvarref};
   61: undef $perlvarref;
   62: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
   63: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
   64: 
   65: # --------------------------------------- Make sure that LON-CAPA is configured
   66: # I only test for one thing here (lonHostID).  This is just a safeguard.
   67: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
   68:    print("Unconfigured machine.\n");
   69:    $emailto=$perlvar{'lonSysEMail'};
   70:    $hostname=`/bin/hostname`;
   71:    chop $hostname;
   72:    $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
   73:    $subj="LON: Unconfigured machine $hostname";
   74:    system("echo 'Unconfigured machine $hostname.' |\
   75:  mailto $emailto -s '$subj' > /dev/null");
   76:     exit 1;
   77: }
   78: 
   79: # ----------------------------- Make sure this process is running from user=www
   80: my $wwwid=getpwnam('www');
   81: if ($wwwid!=$<) {
   82:    print("User ID mismatch.  This program must be run as user 'www'\n");
   83:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
   84:    $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
   85:    system("echo 'User ID mismatch.  loncron must be run as user www.' |\
   86:  mailto $emailto -s '$subj' > /dev/null");
   87:    exit 1;
   88: }
   89: 
   90: # ------------------------------------------------------------- Read hosts file
   91: {
   92:     my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
   93: 
   94:     while (my $configline=<$config>) {
   95:        my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
   96:        $hostname{$id}=$name;
   97:        $hostdom{$id}=$domain;
   98:        $hostrole{$id}=$role;
   99:        $hostip{$id}=$ip;
  100:        if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
  101: 	   $libserv{$id}=$name;
  102:        }
  103:     }
  104: }
  105: 
  106: # ------------------------------------------------------ Read spare server file
  107: {
  108:     my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
  109: 
  110:     while (my $configline=<$config>) {
  111:        chomp($configline);
  112:        if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
  113:           $spareid{$configline}=1;
  114:        }
  115:     }
  116: }
  117: 
  118: # ---------------------------------------------------------------- Start report
  119: 
  120: $statusdir="/home/httpd/html/lon-status";
  121: 
  122: $errors=0;
  123: $warnings=0;
  124: $notices=0;
  125: 
  126: $now=time;
  127: $date=localtime($now);
  128: 
  129: {
  130: my $fh=IO::File->new(">$statusdir/newstatus.html");
  131: 
  132: print $fh (<<ENDHEADERS);
  133: <html>
  134: <head>
  135: <title>LON Status Report $perlvar{'lonHostID'}</title>
  136: </head>
  137: <body bgcolor="#AAAAAA">
  138: <a name="top">
  139: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
  140: <h2>$date ($now)</h2>
  141: <ol>
  142: <li><a href="#configuration">Configuration</a>
  143: <li><a href="#machine">Machine Information</a>
  144: <li><a href="#tmp">Temporary Files</a>
  145: <li><a href="#tokens">Session Tokens</a>
  146: <li><a href="#httpd">httpd</a>
  147: <li><a href="#lonsql">lonsql</a>
  148: <li><a href="#lond">lond</a>
  149: <li><a href="#lonc">lonc</a>
  150: <li><a href="#lonnet">lonnet</a>
  151: <li><a href="#connections">Connections</a>
  152: <li><a href="#delayed">Delayed Messages</a>
  153: <li><a href="#errcount">Error Count</a>
  154: </ol>
  155: <hr>
  156: <a name="configuration">
  157: <h2>Configuration</h2>
  158: <h3>PerlVars</h3>
  159: <table border=2>
  160: ENDHEADERS
  161: 
  162: foreach $varname (keys %perlvar) {
  163:     print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
  164: }
  165: print $fh "</table><h3>Hosts</h3><table border=2>";
  166: foreach $id (keys %hostname) {
  167: print $fh 
  168:     "<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
  169: print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
  170: }
  171: print $fh "</table><h3>Spare Hosts</h3><ol>";
  172: foreach $id (keys %spareid) {
  173:     print $fh "<li>$id\n";
  174: }
  175: 
  176: print $fh "</ol>\n";
  177: 
  178: # --------------------------------------------------------------------- Machine
  179: 
  180: print $fh '<hr><a name="machine"><h2>Machine Information</h2>';
  181: print $fh "<h3>loadavg</h3>";
  182: 
  183: open (LOADAVGH,"/proc/loadavg");
  184: $loadavg=<LOADAVGH>;
  185: close (LOADAVGH);
  186: 
  187: print $fh "<tt>$loadavg</tt>";
  188: 
  189: @parts=split(/\s+/,$loadavg);
  190: if ($parts[1]>4.0) {
  191:     $errors++;
  192: } elsif ($parts[1]>2.0) {
  193:     $warnings++;
  194: } elsif ($parts[1]>1.0) {
  195:     $notices++;
  196: }
  197: 
  198: print $fh "<h3>df</h3>";
  199: print $fh "<pre>";
  200: 
  201: open (DFH,"df|");
  202: while ($line=<DFH>) { 
  203:    print $fh "$line"; 
  204:    @parts=split(/\s+/,$line);
  205:    $usage=$parts[4];
  206:    $usage=~s/\W//g;
  207:    if ($usage>90) { 
  208:       $warnings++;
  209:       $notices++; 
  210:    } elsif ($usage>80) {
  211:       $warnings++;
  212:    } elsif ($usage>60) {
  213:       $notices++;
  214:    }
  215:    if ($usage>95) { $warnings++; $warnings++ }
  216: }
  217: close (DFH);
  218: print $fh "</pre>";
  219: 
  220: 
  221: print $fh "<h3>ps</h3>";
  222: print $fh "<pre>";
  223: $psproc=0;
  224: 
  225: open (PSH,"ps -aux|");
  226: while ($line=<PSH>) { 
  227:    print $fh "$line"; 
  228:    $psproc++;
  229: }
  230: close (PSH);
  231: print $fh "</pre>";
  232: 
  233: if ($psproc>200) { $notices++; }
  234: if ($psproc>250) { $notices++; }
  235: 
  236: &errout($fh);
  237: 
  238: # --------------------------------------------------------------- clean out tmp
  239: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
  240: $cleaned=0;
  241: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
  242:                           my ($dev,$ino,$mode,$nlink,
  243:                               $uid,$gid,$rdev,$size,
  244:                               $atime,$mtime,$ctime,
  245:                               $blksize,$blocks)=stat($fname);
  246:                           $now=time;
  247:                           $since=$now-$mtime;
  248:                           if ($since>$perlvar{'lonExpire'}) {
  249:                               $cleaned++;
  250:                               unlink("$fname");
  251:                           }
  252:     
  253: }
  254: print $fh "Cleaned up ".$cleaned." files.";
  255: 
  256: # ------------------------------------------------------------ clean out lonIDs
  257: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
  258: $cleaned=0;
  259: $active=0;
  260: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
  261:                           my ($dev,$ino,$mode,$nlink,
  262:                               $uid,$gid,$rdev,$size,
  263:                               $atime,$mtime,$ctime,
  264:                               $blksize,$blocks)=stat($fname);
  265:                           $now=time;
  266:                           $since=$now-$mtime;
  267:                           if ($since>$perlvar{'lonExpire'}) {
  268:                               $cleaned++;
  269:                               print $fh "Unlinking $fname<br>";
  270:                               unlink("$fname");
  271:                           } else {
  272:                               $active++;
  273:                           }
  274:     
  275: }
  276: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
  277: print $fh "<h3>$active open session(s)</h3>";
  278: 
  279: # ----------------------------------------------------------------------- httpd
  280: 
  281: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
  282: 
  283: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
  284: while ($line=<DFH>) { print $fh "$line" };
  285: close (DFH);
  286: 
  287: print $fh "</pre><h3>Error Log</h3><pre>";
  288: 
  289: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
  290: while ($line=<DFH>) { 
  291:    print $fh "$line";
  292:    if ($line=~/\[error\]/) { $notices++; } 
  293: };
  294: close (DFH);
  295: print $fh "</pre>";
  296: &errout($fh);
  297: 
  298: 
  299: # ---------------------------------------------------------------------- lonsql
  300: 
  301: my $restartflag=1;
  302: if ($perlvar{'lonRole'} eq "library") {
  303: 
  304:     print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
  305:     print "lonsql\n";
  306:     if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
  307: 	open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
  308: 	while ($line=<DFH>) { 
  309: 	    print $fh "$line";
  310: 	    if ($line=~/INFO/) { $notices++; }
  311: 	    if ($line=~/WARNING/) { $notices++; }
  312: 	    if ($line=~/CRITICAL/) { $warnings++; }
  313: 	};
  314: 	close (DFH);
  315:     }
  316:     print $fh "</pre>";
  317:     
  318:     my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
  319:  
  320:     $restartflag=1;
  321:    
  322:     if (-e $lonsqlfile) {
  323: 	my $lfh=IO::File->new("$lonsqlfile");
  324: 	my $lonsqlpid=<$lfh>;
  325: 	chomp($lonsqlpid);
  326: 	if (kill 0 => $lonsqlpid) {
  327: 	    print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
  328: 	    $restartflag=0;
  329: 	} else {
  330: 	    $errors++; $errors++;
  331: 	    print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
  332: 		$restartflag=1;
  333: 	print $fh 
  334: 	    "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
  335: 	}
  336:     }
  337:     if ($restartflag==1) {
  338: 	$errors++;
  339: 	         print $fh '<br><font color="red">Killall lonsql: '.
  340:                     system('killall lonsql').' - ';
  341:                     sleep 60;
  342:                     print $fh unlink($lonsqlfile).' - '.
  343:                               system('killall -9 lonsql').
  344:                     '</font><br>';
  345: 	print $fh "<h3>lonsql not running, trying to start</h3>";
  346: 	system(
  347:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
  348: 	sleep 10;
  349: 	if (-e $lonsqlfile) {
  350: 	    print $fh "Seems like it started ...<p>";
  351: 	    my $lfh=IO::File->new("$lonsqlfile");
  352: 	    my $lonsqlpid=<$lfh>;
  353: 	    chomp($lonsqlpid);
  354: 	    sleep 30;
  355: 	    if (kill 0 => $lonsqlpid) {
  356: 		print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
  357: 	    } else {
  358: 		$errors++; $errors++;
  359: 		print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
  360: 		print $fh "Give it one more try ...<p>";
  361: 		system(
  362:  "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
  363: 		sleep 10;
  364: 	    }
  365: 	} else {
  366: 	    print $fh "Seems like that did not work!<p>";
  367: 	    $errors++;
  368: 	}
  369: 	if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
  370: 	    print $fh "<p><pre>";
  371: 	    open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
  372: 	    while ($line=<DFH>) { 
  373: 		print $fh "$line";
  374: 		if ($line=~/WARNING/) { $notices++; }
  375: 		if ($line=~/CRITICAL/) { $notices++; }
  376: 	    };
  377: 	    close (DFH);
  378: 	    print $fh "</pre>";
  379: 	}
  380:     }
  381: 
  382:     $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
  383: 
  384:     my ($dev,$ino,$mode,$nlink,
  385: 	$uid,$gid,$rdev,$size,
  386: 	$atime,$mtime,$ctime,
  387: 	$blksize,$blocks)=stat($fname);
  388: 
  389:     if ($size>40000) {
  390: 	print $fh "Rotating logs ...<p>";
  391: 	rename("$fname.2","$fname.3");
  392: 	rename("$fname.1","$fname.2");
  393: 	rename("$fname","$fname.1");
  394:     }
  395: 
  396:     &errout($fh);
  397: }
  398: # ------------------------------------------------------------------------ lond
  399: 
  400: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
  401: print "lond\n";
  402: 
  403: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
  404: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
  405: while ($line=<DFH>) { 
  406:    print $fh "$line";
  407:    if ($line=~/INFO/) { $notices++; }
  408:    if ($line=~/WARNING/) { $notices++; }
  409:    if ($line=~/CRITICAL/) { $warnings++; }
  410: };
  411: close (DFH);
  412: }
  413: print $fh "</pre>";
  414: 
  415: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
  416: 
  417: $restartflag=1;
  418: if (-e $londfile) {    
  419:    my $lfh=IO::File->new("$londfile");
  420:    my $londpid=<$lfh>;
  421:    chomp($londpid);
  422:    if (kill 0 => $londpid) {
  423:       print $fh "<h3>lond at pid $londpid responding, sending USR1</h3>";
  424:       kill USR1 => $londpid;
  425:       $restartflag=0;
  426:    } else {
  427:       $errors++;
  428:       print $fh "<h3>lond at pid $londpid not responding</h3>";
  429:       $restartflag=1;
  430:       print $fh 
  431: 	  "<h3>Decided to clean up stale .pid file and restart lond</h3>";
  432:    }
  433: } 
  434: if ($restartflag==1) {
  435:    $errors++;
  436: 	  print $fh '<br><font color="red">Killall lond: '.
  437:                     system('killall lond').' - ';
  438:           sleep 60;
  439:           print $fh unlink($londfile).' - '.system('killall -9 lond').
  440:                     '</font><br>';
  441:    print $fh "<h3>lond not running, trying to start</h3>";
  442:    system(
  443:      "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
  444:    sleep 10;
  445:    if (-e $londfile) {
  446:        print $fh "Seems like it started ...<p>";
  447:        my $lfh=IO::File->new("$londfile");
  448:        my $londpid=<$lfh>;
  449:        chomp($londpid);
  450:        sleep 30;
  451:        if (kill 0 => $londpid) {
  452:           print $fh "<h3>lond at pid $londpid responding</h3>";
  453:        } else {
  454:           $errors++; $errors++;
  455:           print $fh "<h3>lond at pid $londpid not responding</h3>";
  456:           print $fh "Give it one more try ...<p>";
  457: 	  system(
  458:  "$perlvar{'lonDaemons'}/lond 2>>$perlvar{'lonDaemons'}/logs/lond_errors");
  459:           sleep 10;
  460:        }
  461:    } else {
  462:        print $fh "Seems like that did not work!<p>";
  463:        $errors++;
  464:    }
  465:    if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
  466:     print $fh "<p><pre>";
  467:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lond.log|");
  468:     while ($line=<DFH>) { 
  469:       print $fh "$line";
  470:       if ($line=~/WARNING/) { $notices++; }
  471:       if ($line=~/CRITICAL/) { $notices++; }
  472:     };
  473:     close (DFH);
  474:     print $fh "</pre>";
  475:    }
  476: }
  477: 
  478: $fname="$perlvar{'lonDaemons'}/logs/lond.log";
  479: 
  480:                           my ($dev,$ino,$mode,$nlink,
  481:                               $uid,$gid,$rdev,$size,
  482:                               $atime,$mtime,$ctime,
  483:                               $blksize,$blocks)=stat($fname);
  484: 
  485: if ($size>40000) {
  486:     print $fh "Rotating logs ...<p>";
  487:     rename("$fname.2","$fname.3");
  488:     rename("$fname.1","$fname.2");
  489:     rename("$fname","$fname.1");
  490: }
  491: 
  492: &errout($fh);
  493: # ------------------------------------------------------------------------ lonc
  494: 
  495: print $fh '<hr><a name="lonc"><h2>lonc</h2><h3>Log</h3><pre>';
  496: print "lonc\n";
  497: 
  498: if (-e "$perlvar{'lonDaemons'}/logs/lonc.log"){
  499: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lonc.log|");
  500: while ($line=<DFH>) { 
  501:    print $fh "$line";
  502:    if ($line=~/INFO/) { $notices++; }
  503:    if ($line=~/WARNING/) { $notices++; }
  504:    if ($line=~/CRITICAL/) { $warnings++; }
  505: };
  506: close (DFH);
  507: }
  508: print $fh "</pre>";
  509: 
  510: my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid";
  511: 
  512: $restartflag=1;
  513: if (-e $loncfile) {
  514:    my $lfh=IO::File->new("$loncfile");
  515:    my $loncpid=<$lfh>;
  516:    chomp($loncpid);
  517:    if (kill 0 => $loncpid) {
  518:       print $fh "<h3>lonc at pid $loncpid responding, sending USR1</h3>";
  519:       kill USR1 => $loncpid;
  520:       $restartflag=0;
  521:    } else {
  522:       $errors++;
  523:       print $fh "<h3>lonc at pid $loncpid not responding</h3>";
  524:       # Solution: kill parent and children processes, remove .pid and restart
  525: 	  $restartflag=1;
  526:       print $fh 
  527: 	  "<h3>Decided to clean up stale .pid file and restart lonc</h3>";
  528:    }
  529: } 
  530: if ($restartflag==1) {
  531:    $errors++;
  532: 	  print $fh '<br><font color="red">Killall lonc: '.
  533: 	            system('killall lonc').' - ';
  534:           sleep 60;
  535:           print $fh unlink($loncfile).' - '.system('killall -9 lonc').
  536:                     '</font><br>';
  537:    print $fh "<h3>lonc not running, trying to start</h3>";
  538: 	system(
  539:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
  540:    sleep 10;
  541:    if (-e $loncfile) {
  542:        print $fh "Seems like it started ...<p>";
  543:        my $lfh=IO::File->new("$loncfile");
  544:        my $loncpid=<$lfh>;
  545:        chomp($loncpid);
  546:        sleep 30;
  547:        if (kill 0 => $loncpid) {
  548:           print $fh "<h3>lonc at pid $loncpid responding</h3>";
  549:        } else {
  550:           $errors++; $errors++;
  551:           print $fh "<h3>lonc at pid $loncpid not responding</h3>";
  552:           print $fh "Give it one more try ...<p>";
  553:  	  system(
  554:  "$perlvar{'lonDaemons'}/lonc 2>>$perlvar{'lonDaemons'}/logs/lonc_errors");
  555:           sleep 10;
  556:        }
  557:    } else {
  558:        print $fh "Seems like that did not work!<p>";
  559:        $errors++;
  560:    }
  561:    if (-e "$perlvar{'lonDaemons'}/logs/lonc.log") {
  562:     print $fh "<p><pre>";
  563:     open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonc.log|");
  564:     while ($line=<DFH>) { 
  565:       print $fh "$line";
  566:       if ($line=~/WARNING/) { $notices++; }
  567:       if ($line=~/CRITICAL/) { $notices++; }
  568:     };
  569:     close (DFH);
  570:     print $fh "</pre>";
  571:    }
  572: }
  573: 
  574: $fname="$perlvar{'lonDaemons'}/logs/lonc.log";
  575: 
  576:                           my ($dev,$ino,$mode,$nlink,
  577:                               $uid,$gid,$rdev,$size,
  578:                               $atime,$mtime,$ctime,
  579:                               $blksize,$blocks)=stat($fname);
  580: 
  581: if ($size>40000) {
  582:     print $fh "Rotating logs ...<p>";
  583:     rename("$fname.2","$fname.3");
  584:     rename("$fname.1","$fname.2");
  585:     rename("$fname","$fname.1");
  586: }
  587: 
  588:    
  589: &errout($fh);
  590: # ---------------------------------------------------------------------- lonnet
  591: 
  592: print $fh '<hr><a name="lonnet"><h2>lonnet</h2><h3>Temp Log</h3><pre>';
  593: print "lonnet\n";
  594: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.log"){
  595: open (DFH,"tail -n50 $perlvar{'lonDaemons'}/logs/lonnet.log|");
  596: while ($line=<DFH>) { 
  597:     print $fh "$line";
  598: };
  599: close (DFH);
  600: }
  601: print $fh "</pre><h3>Perm Log</h3><pre>";
  602: 
  603: if (-e "$perlvar{'lonDaemons'}/logs/lonnet.perm.log") {
  604:     open(DFH,"tail -n10 $perlvar{'lonDaemons'}/logs/lonnet.perm.log|");
  605: while ($line=<DFH>) { 
  606:    print $fh "$line";
  607: };
  608: close (DFH);
  609: } else { print $fh "No perm log\n" }
  610: 
  611: $fname="$perlvar{'lonDaemons'}/logs/lonnet.log";
  612: 
  613:                           my ($dev,$ino,$mode,$nlink,
  614:                               $uid,$gid,$rdev,$size,
  615:                               $atime,$mtime,$ctime,
  616:                               $blksize,$blocks)=stat($fname);
  617: 
  618: if ($size>40000) {
  619:     print $fh "Rotating logs ...<p>";
  620:     rename("$fname.2","$fname.3");
  621:     rename("$fname.1","$fname.2");
  622:     rename("$fname","$fname.1");
  623: }
  624: 
  625: print $fh "</pre>";
  626: &errout($fh);
  627: # ----------------------------------------------------------------- Connections
  628: 
  629: print $fh '<hr><a name="connections"><h2>Connections</h2>';
  630: 
  631: print $fh "<table border=2>";
  632: foreach $tryserver (keys %hostname) {
  633: 
  634:     $answer=reply("pong",$tryserver);
  635:     if ($answer eq "$tryserver:$perlvar{'lonHostID'}") {
  636: 	$result="<b>ok</b>";
  637:     } else {
  638:         $result=$answer;
  639:         $warnings++;
  640:         if ($answer eq 'con_lost') { $warnings++; }
  641:     }
  642:     print $fh "<tr><td>$tryserver</td><td>$result</td></tr>\n";
  643: 
  644: }
  645: print $fh "</table>";
  646: 
  647: &errout($fh);
  648: # ------------------------------------------------------------ Delayed messages
  649: 
  650: print $fh '<hr><a name="delayed"><h2>Delayed Messages</h2>';
  651: print "buffers\n";
  652: 
  653: print $fh '<h3>Scanning Permanent Log</h3>';
  654: 
  655: $unsend=0;
  656: {
  657:     my $dfh=IO::File->new("$perlvar{'lonDaemons'}/logs/lonnet.perm.log");
  658:     while ($line=<$dfh>) {
  659: 	($time,$sdf,$dserv,$dcmd)=split(/:/,$line);
  660:         if ($sdf eq 'F') { 
  661: 	    $local=localtime($time);
  662:             print "<b>Failed: $time, $dserv, $dcmd</b><br>";
  663:             $warnings++;
  664:         }
  665:         if ($sdf eq 'S') { $unsend--; }
  666:         if ($sdf eq 'D') { $unsend++; }
  667:     }
  668: }
  669: print $fh "Total unsend messages: <b>$unsend</b><p>\n";
  670: $warnings=$warnings+5*$unsend;
  671: 
  672: print $fh "<h3>Outgoing Buffer</h3>";
  673: 
  674: open (DFH,"ls -lF $perlvar{'lonSockDir'}/delayed|");
  675: while ($line=<DFH>) { 
  676:     print $fh "$line<br>";
  677: };
  678: close (DFH);
  679: 
  680: # ------------------------------------------------------------------------- End
  681: print $fh "<a name=errcount>\n";
  682: $totalcount=$notices+4*$warnings+100*$errors;
  683: &errout($fh);
  684: print $fh "<h1>Total Error Count: $totalcount</h1>";
  685: $now=time;
  686: $date=localtime($now);
  687: print $fh "<hr>$date ($now)</body></html>\n";
  688: print "writing done\n";
  689: }
  690: 
  691: rename ("$statusdir/newstatus.html","$statusdir/index.html");
  692: 
  693: if ($totalcount>200) {
  694:    print "mailing\n";
  695:    $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
  696:    $subj="LON: $perlvar{'lonHostID'} E:$errors W:$warnings N:$notices"; 
  697:    system(
  698:  "metasend -b -t $emailto -s '$subj' -f $statusdir/index.html -m text/html");
  699: }
  700: 1;
  701: 
  702: 
  703: 
  704: 
  705: 
  706: 
  707: 
  708: 

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