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