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