Quote:
Originally Posted by Kayla
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