[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Re: [LIP] CPU Info



> > And what exactly is this Equation that you mentioned ?!

I got the Algo to calculate system|user|nice loads from:
procps-2.0.6/top.c and related files (You need to download the procps
package)

Here's a Quick perl script to get the loads using HTTP:
(You need to modify it for SMPs)
-------------------8<-------------------8<-----------------------

use CGI;
print "Content-Type: text/html\n";
print "Expires: Fri, 25 Feb 2000 06:49:25 GMT\n";
print "Pragma: no-cache\n";
print "Cache-Control: no-cache\n";
print "\n";
    
$uptime=`cat /proc/stat|grep cpu`;
if ($uptime =~ /.*cpu\s*(\S*)\s(\S*)\s*(\S*)\s(\S*)/)
{   
        $useri = $1;
        $nicei = $2;
        $systi = $3;
#       $idlei = $4;
}   
sleep 1;
$uptime=`cat /proc/stat|grep cpu`;
if ($uptime =~ /.*cpu\s*(\S*)\s(\S*)\s*(\S*)\s(\S*)/)
{
        $user = ($useri - $1);
        $nice = ($nicei - $2);
        $syst = ($systi - $3);
#       $idle = ($idlei - $4);
    
        $sum = $user + $nice + $syst + $idle;
 
        $user1 = ($user * 1000) / $sum;
        $nice1 = ($nice * 1000) / $sum;
        $syst1 = ($syst * 1000) / $sum;
    
        $userload = ($user1 % 1000) ;
        $niceload = ($nice1 % 1000) ;
        $systload = ($syst1 % 1000) ;
    
        print '<HTML><HEAD><META HTTP-EQUIV="Expires" CONTENT="Tue, 20
Aug1996 14:25:
27 GMT"></HEAD>';
        print "\n$userload\n";
        print "$systload\n";
        print "$niceload\n";
#       print "</HTML>";
}   
    

-- 
Bowie's Theorem:
	If an experiment works, you must be using the wrong equipment.