Zef Hemel
Thu 14th Jun '01, 7:00am
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:
http://keybulletin.xnull.com/drawload.php
I think it's really cool.
chrispadfield
Thu 14th Jun '01, 7:29am
that is cool. Any chance of posting the code you are using?
Zef Hemel
Thu 14th Jun '01, 10:20am
Sure, this is the serverload.php (executed every minute by a cronjob):
<?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);
?>
This is the code for the drawload.php (the chart I just showed you):
<?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);
?>
I have a customized version for the avatar (in which serverload.php generates the .jpg image for the avatar, so it doesn't have to be regenerated every hit the avatar gets.
chrispadfield
Thu 14th Jun '01, 10:44am
cool! will try this soon.
Stallion
Thu 14th Jun '01, 10:49am
The only problem is your avatar is hosted on the server of the forum. So even when you set your avatar in the user CP, it stores the current load image...regardless of how often you update the avatar.
What you need to do is add a section to your script which will update the new avatar on the server. Not too hard to do if you have an understanding of HTTP and the file upload specifications.
Zef Hemel
Thu 14th Jun '01, 10:59am
You mean that, vBulletin automatically downloads the avatar and stores it in it's database? Hmm, that's to bad. I'd say the easiest thing to do would be to create a hack that allowed external avatars being loaded from another server. Or use other bulletin board software ;) (but I doubt if that's an option).
Jake Bunce
Thu 14th Jun '01, 2:21pm
multiple domain resolutions = bad. :D
Stallion
Thu 14th Jun '01, 9:58pm
Plus there are some privacy issues with doing that... ;)
vBulletin® v3.8.0 Release Candidate 1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.