#!/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 ="";
$oldpage = "
\n$oldpage";
print "Content-type: text/html\n\n";
print "";
print "$fontc $list[3]
$fontc $list[6]
$fontc $list[7]
$fontc $date2
% CPU | run/all | last PID | Time |