Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This html file uses this code
<BODY> This is the Monitor Script<BR><BR> <FORM NAME="myForm" 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 ""; 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="$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.

In reply to Server Monitor via Web by BigJoe

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2018-05-26 04:36 GMT
    Find Nodes?
      Voting Booth?