The PERL Script looks like:<BODY> This is the Monitor Script<BR><BR> <FORM NAME="myForm" ACTION=monitor.pl METHOD="POST"> <TABLE CELLPADDING=2 CELLSPACING=0> <TR><TD WIDTH=50>Start a new log:</TD><TD> <SELECT NAME="new"> <OPTION>TRUE <OPTION>FALSE </SELECT></TD><TD>number of rows on the page:</TD><TD> <SELECT NAME="numofr"> <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8 <OPTION>9 <OPTION>10 <OPTION>20 <OPTION>50 <OPTION>100 </SELECT></TD> <TD>Time Interval (approx sec(s)):</TD><TD> <SELECT NAME="timers"> <OPTION>1 <OPTION>2 <OPTION>4 <OPTION>5 <OPTION>7 <OPTION>9 <OPTION>10 <OPTION>20 <OPTION>50 <OPTION>100 </SELECT></TD> </TR> </TR> <TR><TD COLSPAN=2><INPUT TYPE=SUBMIT VALUE="GO"></TD></TR> </TABLE> </FORM> </BODY></HTML>
And the text file needs to be history.txt and it needs to be read and writable.#!/usr/bin/perl require "cgi-lib.pl"; ReadParse(*in); $goodcolor="GREEN"; $medcolor="ORANGE"; $badcolor="RED"; $old="history.txt"; $numofrows=8; $startfile="time.txt"; $timing=5; if($in{numofr} >= 1) { $numofrows=$in{numofr}; } if($in{timers} >= 1) { $timing=$in{timers}; } @months = ('Jan','Feb','Mar','Apr','May','June', 'July','Aug','Sept','Oct','Nov','Dec'); @days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); ($sec,$min,$hour,$mday,$mon,$year,$wday) =(localtime(time))[0,1,2,3,4, +5,6]; $year=$year+1900; $date = " $days[$wday], $months[$mon]/$mday/$year $hour:$min:$sec"; $date2 = " $hour:$min:$sec"; $loada=`more /proc/loadavg`; open(OLDPAGE, $old); $filesize = -s OLDPAGE; read(OLDPAGE, $oldpage, $filesize); close(OLDPAGE); open(OLDPAGE2, $startfile); $filesize = -s OLDPAGE; read(OLDPAGE2, $heading, $filesize); close(OLDPAGE2); if($in{new}) { $heading="This script started $date"; open(DUMPTIME, ">$startfile"); print DUMPTIME $heading; $oldpage=""; close(DUMPTIME); $numofrows--; } $script="monitor.pl?numofr=$numofrows&timers=$timing"; my @list = split /\s+/, $loada; if ($list[0] >= 80) { $color=$badcolor; }elsif ($list[0] >= 55){ $color=$medcolor; }else{ $color=$goodcolor; } $fontc ="<FONT COLOR=\"$color\">"; $oldpage = "<TR> <TD>$fontc $list[3]</TD> <TD>$fontc $list[6]</TD> <TD>$fontc $list[7]</TD> <TD>$fontc $date2</TD> </TR></FONT>\n$oldpage"; print "Content-type: text/html\n\n"; print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"$timing;URL=$script\">"; + print "<HTML><BODY><CENTER>$heading<BR><TABLE cols=4 cellpadding=10 border=1>"; print "<TR><TD>% CPU</TD><TD>run/all</TD><TD>last PID</TD><TD>Time</TD +></TR>"; print "$oldpage"; print "</TABLE></BODY></HTML>"; my @bigarray = split /\n+/, $oldpage; @bigarray=@bigarray[0 .. ($numofrows*6)]; open(FILEOUT2, ">$old"); foreach (@bigarray) { print FILEOUT2 "$_ \n";} close(FILEOUT2);
In reply to Server Monitor via Web by BigJoe
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |