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