Category: | Web admin tools |
Author/Contact Info | bigJoe Big_Joe1008@linuxstart.com |
Description: | This is a Quick script to keep track of the load on the server. There are 3 files that are needed to be made. The HTML file to access it the history text file and the monitor.pl script. The HTML diplay is very generic. click here to see it work |
This html file uses this code
<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>The PERL Script looks like: #!/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);And the text file needs to be history.txt and it needs to be read and writable. |
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Server Monitor via Web
by KM (Priest) on May 23, 2000 at 04:35 UTC | |
by BigJoe (Curate) on May 23, 2000 at 05:55 UTC | |
by KM (Priest) on May 23, 2000 at 06:11 UTC | |
RE: Server Monitor via Web
by KM (Priest) on May 23, 2000 at 04:43 UTC | |
by Sylvyr (Initiate) on Jun 06, 2005 at 20:00 UTC | |
by BigJoe (Curate) on May 23, 2000 at 05:51 UTC |
Back to
Code Catacombs