View Single Post
Old February 1st, 2007, 10:41 PM   #21 (permalink)
twirp
DemonicAngel
Super #1
 
twirp's Avatar
 
Joined in Aug 2004
Lives in Wherever The World Takes Me
Hosted on Pass76
1,842 posts
Gave thanks: 28
Thanked 35 times
Quote:
Originally Posted by Kayla View Post
Twirp, we need instructions for that ASAP!
This is what I did...:
PHP Code:
<?php
/* name:        severload.php
   Author:      Jesse Chilcott
   Description: This script creates a horizontal meter that shows the server load
   Useage:      link to the script as if it is an image
*/

/* get server load */
        
if (file_exists("/proc/stat") == true)
        {
            
//$fp = @fopen("/proc/loadavg", "r");
            //if (empty($fp) == false)
            //{
            
if($lost_averages = @file_get_contents("/proc/stat")){
                
//$load_averages = @fread($fp, 64);
                
$load_averages = @file_get_contents('/proc/loadavg');
                
$loadavg explode(" "$load_averages);
                
//fclose($fp);
                
$loadav $loadavg[0];  // we don't want to many digits or it will overlap the meter
                
$data explode(" "$lost_averages);
                
$user $data[2];
                
$nice $data[3];
                
$system $data[4];
                
$idle $data[5];
                
$total $user $nice $system $idle;
                
                
$meterwidth = (1-((($idle  100.0)/$total) / 100.0)) * 205;
                
$percent round((1-((($idle  100.0)/$total) / 100.0)) * 1000) / 10;
            }
            else
            {
                
$loadav   "error";
            }
        }
        else
        {
            
$loadav   "error";
        }


header("Content-type: image/png");

/* get and set more image and font details */
$im imagecreatefrompng("dn_angel_468x60.png");

$width imagesx($im);
$height imagesy($im);

$xLoc 250;
$yLoc 30;

$green imagecreatefrompng("green_bar.png");
$red imagecreatefrompng("red_bar.png");
$white imagecolorallocate($im,255,255,255);


/* do meter bar */
if ($loadav != "error") {
    
imagecopyresized($im,$green,$xLoc,$yLoc,0,0,205,15,10,10);
    
imagecopyresized($im,$red,$xLoc,$yLoc,0,0,$meterwidth,15,10,10);
    
$loadav round($loadav 10) / 10;
    
//imagefilledrectangle ( $im, 48 ,4, 48 + $meterwidth, $height-6, $metercolor );
    //imagerectangle ( $im, 48,4, 76, $height-6, $bordercolor2 );
}
imagestring($im,3,$xLoc,$yLoc'Load: '.$loadav.', CPU Useage: '.$percent.'%',$white);
/* output gif image to browser */
imagepng($im);
imagedestroy($im);

//echo "\n".$loadav.":".$meterwidth;
?>
It probably increases the load more than need be... (if it is, I'll change it)

The images were:
http://statimg.lost-whisper.info/dn_angel_468x60.png
http://statimg.lost-whisper.info/red_bar.png
http://statimg.lost-whisper.info/green_bar.png
__________________
You wear Vans so high school kids will think that you can skate. He wears Vans because he can skate. TwiRp wears Vans because they were on sale. Pass76 wants Vans.
twirp is offline   Reply With Quote
These users thank twirp for this great post!
Bigjohn (February 2nd, 2007), Edwin (February 3rd, 2007), mgk (April 7th, 2007)