Annotation of loncom/loncron, revision 1.24
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.24 ! www 16: # 09/04,09/06 Gerd Kortemeyer
! 17:
! 18: $|=1;
1.1 albertel 19:
20: use IO::File;
21: use IO::Socket;
22:
23: # -------------------------------------------------- Non-critical communication
24: sub reply {
25: my ($cmd,$server)=@_;
26: my $peerfile="$perlvar{'lonSockDir'}/$server";
27: my $client=IO::Socket::UNIX->new(Peer =>"$peerfile",
28: Type => SOCK_STREAM,
29: Timeout => 10)
30: or return "con_lost";
31: print $client "$cmd\n";
32: my $answer=<$client>;
33: chomp($answer);
34: if (!$answer) { $answer="con_lost"; }
35: return $answer;
36: }
37:
38: # --------------------------------------------------------- Output error status
39:
40: sub errout {
41: my $fh=shift;
42: print $fh (<<ENDERROUT);
43: <p><table border=2 bgcolor="#CCCCCC">
44: <tr><td>Notices</td><td>$notices</td></tr>
45: <tr><td>Warnings</td><td>$warnings</td></tr>
46: <tr><td>Errors</td><td>$errors</td></tr>
47: </table><p><a href="#top">Top</a><p>
48: ENDERROUT
49: }
50:
51: # ================================================================ Main Program
52:
53: # ------------------------------------------------------------ Read access.conf
54: {
55: my $config=IO::File->new("/etc/httpd/conf/access.conf");
56:
57: while (my $configline=<$config>) {
58: if ($configline =~ /PerlSetVar/) {
59: my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
60: $perlvar{$varname}=$varvalue;
61: }
62: }
1.19 harris41 63: delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed
64: delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed
1.13 harris41 65: }
66:
1.14 harris41 67: # --------------------------------------- Make sure that LON-CAPA is configured
68: # I only test for one thing here (lonHostID). This is just a safeguard.
69: if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) {
1.15 harris41 70: print("Unconfigured machine.\n");
1.14 harris41 71: $emailto=$perlvar{'lonSysEMail'};
72: $hostname=`/bin/hostname`;
73: chop $hostname;
74: $hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell
75: $subj="LON: Unconfigured machine $hostname";
76: system("echo 'Unconfigured machine $hostname.' |\
77: mailto $emailto -s '$subj' > /dev/null");
78: exit 1;
79: }
80:
1.13 harris41 81: # ----------------------------- Make sure this process is running from user=www
82: my $wwwid=getpwnam('www');
83: if ($wwwid!=$<) {
1.14 harris41 84: print("User ID mismatch. This program must be run as user 'www'\n");
1.13 harris41 85: $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
86: $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
87: system("echo 'User ID mismatch. loncron must be run as user www.' |\
88: mailto $emailto -s '$subj' > /dev/null");
1.14 harris41 89: exit 1;
1.1 albertel 90: }
91:
92: # ------------------------------------------------------------- Read hosts file
93: {
94: my $config=IO::File->new("$perlvar{'lonTabDir'}/hosts.tab");
95:
96: while (my $configline=<$config>) {
97: my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
98: $hostname{$id}=$name;
99: $hostdom{$id}=$domain;
100: $hostrole{$id}=$role;
101: $hostip{$id}=$ip;
102: if (($role eq 'library') && ($id ne $perlvar{'lonHostID'})) {
103: $libserv{$id}=$name;
104: }
105: }
106: }
107:
108: # ------------------------------------------------------ Read spare server file
109: {
110: my $config=IO::File->new("$perlvar{'lonTabDir'}/spare.tab");
111:
112: while (my $configline=<$config>) {
113: chomp($configline);
114: if (($configline) && ($configline ne $perlvar{'lonHostID'})) {
115: $spareid{$configline}=1;
116: }
117: }
118: }
119:
120: # ---------------------------------------------------------------- Start report
121:
122: $statusdir="/home/httpd/html/lon-status";
123:
124: $errors=0;
125: $warnings=0;
126: $notices=0;
127:
128: $now=time;
129: $date=localtime($now);
130:
131: {
132: my $fh=IO::File->new(">$statusdir/newstatus.html");
133:
134: print $fh (<<ENDHEADERS);
135: <html>
136: <head>
137: <title>LON Status Report $perlvar{'lonHostID'}</title>
138: </head>
1.3 www 139: <body bgcolor="#AAAAAA">
1.1 albertel 140: <a name="top">
141: <h1>LON Status Report $perlvar{'lonHostID'}</h1>
142: <h2>$date ($now)</h2>
143: <ol>
144: <li><a href="#configuration">Configuration</a>
145: <li><a href="#machine">Machine Information</a>
1.11 www 146: <li><a href="#tmp">Temporary Files</a>
147: <li><a href="#tokens">Session Tokens</a>
1.1 albertel 148: <li><a href="#httpd">httpd</a>
1.11 www 149: <li><a href="#lonsql">lonsql</a>
1.1 albertel 150: <li><a href="#lond">lond</a>
151: <li><a href="#lonc">lonc</a>
152: <li><a href="#lonnet">lonnet</a>
153: <li><a href="#connections">Connections</a>
154: <li><a href="#delayed">Delayed Messages</a>
155: <li><a href="#errcount">Error Count</a>
156: </ol>
157: <hr>
158: <a name="configuration">
159: <h2>Configuration</h2>
160: <h3>PerlVars</h3>
161: <table border=2>
162: ENDHEADERS
163:
164: foreach $varname (keys %perlvar) {
165: print $fh "<tr><td>$varname</td><td>$perlvar{$varname}</td></tr>\n";
166: }
167: print $fh "</table><h3>Hosts</h3><table border=2>";
168: foreach $id (keys %hostname) {
169: print $fh
170: "<tr><td>$id</td><td>$hostdom{$id}</td><td>$hostrole{$id}</td>";
171: print $fh "<td>$hostname{$id}</td><td>$hostip{$id}</td></tr>\n";
172: }
173: print $fh "</table><h3>Spare Hosts</h3><ol>";
174: foreach $id (keys %spareid) {
175: print $fh "<li>$id\n";
176: }
177:
178: print $fh "</ol>\n";
179:
180: # --------------------------------------------------------------------- Machine
181:
182: print $fh '<hr><a name="machine"><h2>Machine Information</h2>';
183: print $fh "<h3>loadavg</h3>";
184:
185: open (LOADAVGH,"/proc/loadavg");
186: $loadavg=<LOADAVGH>;
187: close (LOADAVGH);
188:
189: print $fh "<tt>$loadavg</tt>";
190:
191: @parts=split(/\s+/,$loadavg);
1.4 www 192: if ($parts[1]>4.0) {
1.1 albertel 193: $errors++;
194: } elsif ($parts[1]>2.0) {
195: $warnings++;
196: } elsif ($parts[1]>1.0) {
197: $notices++;
198: }
199:
200: print $fh "<h3>df</h3>";
201: print $fh "<pre>";
202:
203: open (DFH,"df|");
204: while ($line=<DFH>) {
205: print $fh "$line";
206: @parts=split(/\s+/,$line);
207: $usage=$parts[4];
208: $usage=~s/\W//g;
209: if ($usage>90) {
1.24 ! www 210: $warnings++;
! 211: $notices++;
1.1 albertel 212: } elsif ($usage>80) {
213: $warnings++;
214: } elsif ($usage>60) {
215: $notices++;
216: }
1.4 www 217: if ($usage>95) { $warnings++; $warnings++ }
1.1 albertel 218: }
219: close (DFH);
220: print $fh "</pre>";
1.24 ! www 221:
! 222:
! 223: print $fh "<h3>ps</h3>";
! 224: print $fh "<pre>";
! 225: $psproc=0;
! 226:
! 227: open (PSH,"ps -aux|");
! 228: while ($line=<PSH>) {
! 229: print $fh "$line";
! 230: $psproc++;
! 231: }
! 232: close (PSH);
! 233: print $fh "</pre>";
! 234:
! 235: if ($psproc>200) { $notices++; }
! 236: if ($psproc>250) { $notices++; }
! 237:
1.1 albertel 238: &errout($fh);
1.11 www 239:
240: # --------------------------------------------------------------- clean out tmp
241: print $fh '<hr><a name="tmp"><h2>Temporary Files</h2>';
242: $cleaned=0;
243: while ($fname=<$perlvar{'lonDaemons'}/tmp/*>) {
244: my ($dev,$ino,$mode,$nlink,
245: $uid,$gid,$rdev,$size,
246: $atime,$mtime,$ctime,
247: $blksize,$blocks)=stat($fname);
248: $now=time;
249: $since=$now-$mtime;
250: if ($since>$perlvar{'lonExpire'}) {
251: $cleaned++;
252: unlink("$fname");
253: }
254:
255: }
256: print $fh "Cleaned up ".$cleaned." files.";
257:
258: # ------------------------------------------------------------ clean out lonIDs
259: print $fh '<hr><a name="tokens"><h2>Session Tokens</h2>';
260: $cleaned=0;
261: $active=0;
262: while ($fname=<$perlvar{'lonIDsDir'}/*>) {
263: my ($dev,$ino,$mode,$nlink,
264: $uid,$gid,$rdev,$size,
265: $atime,$mtime,$ctime,
266: $blksize,$blocks)=stat($fname);
267: $now=time;
268: $since=$now-$mtime;
269: if ($since>$perlvar{'lonExpire'}) {
270: $cleaned++;
271: print $fh "Unlinking $fname<br>";
272: unlink("$fname");
273: } else {
274: $active++;
275: }
276:
277: }
278: print $fh "<p>Cleaned up ".$cleaned." stale session token(s).";
279: print $fh "<h3>$active open session(s)</h3>";
280:
1.1 albertel 281: # ----------------------------------------------------------------------- httpd
282:
283: print $fh '<hr><a name="httpd"><h2>httpd</h2><h3>Access Log</h3><pre>';
284:
1.23 www 285: open (DFH,"tail -n25 /etc/httpd/logs/access_log|");
1.1 albertel 286: while ($line=<DFH>) { print $fh "$line" };
287: close (DFH);
288:
289: print $fh "</pre><h3>Error Log</h3><pre>";
290:
1.23 www 291: open (DFH,"tail -n25 /etc/httpd/logs/error_log|");
1.1 albertel 292: while ($line=<DFH>) {
293: print $fh "$line";
294: if ($line=~/\[error\]/) { $notices++; }
295: };
296: close (DFH);
297: print $fh "</pre>";
298: &errout($fh);
1.5 harris41 299:
300:
1.11 www 301: # ---------------------------------------------------------------------- lonsql
1.22 harris41 302:
303: my $restartflag=1;
1.18 harris41 304: if ($perlvar{'lonRole'} eq "library") {
1.5 harris41 305:
1.11 www 306: print $fh '<hr><a name="lonsql"><h2>lonsql</h2><h3>Log</h3><pre>';
1.23 www 307: print "lonsql\n";
1.5 harris41 308: if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
309: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
310: while ($line=<DFH>) {
311: print $fh "$line";
312: if ($line=~/INFO/) { $notices++; }
313: if ($line=~/WARNING/) { $notices++; }
314: if ($line=~/CRITICAL/) { $warnings++; }
315: };
316: close (DFH);
317: }
318: print $fh "</pre>";
319:
320: my $lonsqlfile="$perlvar{'lonDaemons'}/logs/lonsql.pid";
1.23 www 321:
322: $restartflag=1;
323:
1.5 harris41 324: if (-e $lonsqlfile) {
325: my $lfh=IO::File->new("$lonsqlfile");
326: my $lonsqlpid=<$lfh>;
327: chomp($lonsqlpid);
328: if (kill 0 => $lonsqlpid) {
329: print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
1.22 harris41 330: $restartflag=0;
1.5 harris41 331: } else {
332: $errors++; $errors++;
333: print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
1.22 harris41 334: $restartflag=1;
1.23 www 335: print $fh
336: "<h3>Decided to clean up stale .pid file and restart lonsql</h3>";
1.5 harris41 337: }
1.22 harris41 338: }
339: if ($restartflag==1) {
1.5 harris41 340: $errors++;
1.23 www 341: print $fh '<br><font color="red">Killall lonsql: '.
342: system('killall lonsql').' - ';
343: sleep 60;
344: print $fh unlink($lonsqlfile).' - '.
345: system('killall -9 lonsql').
346: '</font><br>';
1.5 harris41 347: print $fh "<h3>lonsql not running, trying to start</h3>";
1.16 harris41 348: system(
349: "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.24 ! www 350: sleep 10;
1.5 harris41 351: if (-e $lonsqlfile) {
352: print $fh "Seems like it started ...<p>";
353: my $lfh=IO::File->new("$lonsqlfile");
354: my $lonsqlpid=<$lfh>;
355: chomp($lonsqlpid);
1.24 ! www 356: sleep 30;
1.5 harris41 357: if (kill 0 => $lonsqlpid) {
358: print $fh "<h3>lonsql at pid $lonsqlpid responding</h3>";
359: } else {
360: $errors++; $errors++;
361: print $fh "<h3>lonsql at pid $lonsqlpid not responding</h3>";
362: print $fh "Give it one more try ...<p>";
1.16 harris41 363: system(
364: "$perlvar{'lonDaemons'}/lonsql 2>>$perlvar{'lonDaemons'}/logs/lonsql_errors");
1.24 ! www 365: sleep 10;
1.5 harris41 366: }
367: } else {
368: print $fh "Seems like that did not work!<p>";
369: $errors++;
370: }
371: if (-e "$perlvar{'lonDaemons'}/logs/lonsql.log"){
372: print $fh "<p><pre>";
373: open (DFH,"tail -n100 $perlvar{'lonDaemons'}/logs/lonsql.log|");
374: while ($line=<DFH>) {
375: print $fh "$line";
376: if ($line=~/WARNING/) { $notices++; }
377: if ($line=~/CRITICAL/) { $notices++; }
378: };
379: close (DFH);
380: print $fh "</pre>";
381: }
382: }
383:
384: $fname="$perlvar{'lonDaemons'}/logs/lonsql.log";
385:
386: my ($dev,$ino,$mode,$nlink,
387: $uid,$gid,$rdev,$size,
388: $atime,$mtime,$ctime,
389: $blksize,$blocks)=stat($fname);
390:
391: if ($size>40000) {
392: print $fh "Rotating logs ...<p>";
393: rename("$fname.2","$fname.3");
394: rename("$fname.1","$fname.2");
395: rename("$fname","$fname.1");
396: }
397:
398: &errout($fh);
399: }
1.1 albertel 400: # ------------------------------------------------------------------------ lond
401:
402: print $fh '<hr><a name="lond"><h2>lond</h2><h3>Log</h3><pre>';
1.23 www 403: print "lond\n";
1.1 albertel 404:
405: if (-e "$perlvar{'lonDaemons'}/logs/lond.log"){
1.23 www 406: open (DFH,"tail -n25 $perlvar{'lonDaemons'}/logs/lond.log|");
1.1 albertel 407: while ($line=<DFH>) {
408: print $fh "$line";
1.3 www 409: if ($line=~/INFO/) { $notices++; }
1.4 www 410: if ($line=~/WARNING/) { $notices++; }
411: if ($line=~/CRITICAL/) { $warnings++; }
1.1 albertel 412: };
413: close (DFH);
414: }
415: print $fh "</pre>";
416:
417: my $londfile="$perlvar{'lonDaemons'}/logs/lond.pid";
418:
1.22 harris41 419: $restartflag=1;
1.7 harris41 420: if (-e $londfile) {
1.1 albertel 421: my $lfh=IO::File->new("$londfile");
422: my $londpid=<$lfh>;
423: chomp($londpid);
424: if (kill 0 => $londpid) {
425: print $fh "<h3>lond at pid $londpid responding</h3>";
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>