Have been playing with the PHP GD library. Using a cronjob I can now generate a chart of my server's activity in the past 15 minutes (avatar) or past hour:
I think it's really cool.
I think it's really cool.
Welcome to the vBulletin support forums! In our community forums you can receive professional support and assistance with any issues you might have with your vBulletin Products.
Useful Links for Guests:
If you are having problems posting in the relevant areas for your software, please see this topic.
<?php
function loadaverage() {
$path='/proc/loadavg';
if(file_exists($path))
{
$filesize=filesize($path);
$filenum=fopen($path,'r');
$filestuff=@fread($filenum,6);
fclose($filenum);
$loadavg=explode(' ',$filestuff);
}
else
{
$loadavg_raw = exec("uptime");
$loadavg_raw = split("load averages?: ", $loadavg_raw);
$loadavg = explode (',', $loadavg_raw[1]);
}
return (trim($loadavg[0]));
}
$lines = file("loadlog.txt");
if(count($lines)>75)
array_shift($lines);
$lines[] = loadaverage()."\n";
$fp = fopen("loadlog.txt", "w");
for($i=0;$i<count($lines);++$i)
fputs($fp, $lines[$i]);
fclose($fp);
?>
<?php
function drawload($load)
{
global $image, $bg, $green, $maxload;
static $x = 25;
if(!$load)
return false;
$y = 75 - round(75 * ((float)$load/(float)$maxload));
//echo "$load = $x, $y<br>";
ImageFilledRectangle($image, $x, $y, $x+2, 75, $green);
$x += 4;
}
function maxload()
{
global $loads;
$max = 0;
for($i=0;$i<count($loads);++$i)
{
if((float)$loads[$i]>(float)$max)
$max = $loads[$i];
}
return $max;
}
$loads = file("loadlog.txt");
$maxload = maxload();
if($maxload < 3)
$maxload = 3;
$image = ImageCreate(330, 75);
$bg = ImageColorAllocate($image, 0, 0, 0);
$green = ImageColorAllocate($image, 0, 255, 0);
ImageRectangle($image, 0, 0, 330, 75, $black);
for($i=0;$i<count($loads);++$i)
drawload($loads[$i]);
ImageString($image, 1, 0, 0, (float)$maxload, $green);
ImageString($image, 1, 0, 32, (float)((float)$maxload/2), $green);
ImageString($image, 1, 0, 65, "0.00", $green);
Header("Content-type: image/jpeg");
Imagejpeg($image);
ImageDestroy($image);
?>
Comment