|
Searcher
Surpass Staff
Joined in May 2003
Lives in Orlando
24,699 posts
Gave thanks: 943
Thanked 806 times
|
[Self-serve] Server Load Button
Do a little something so Surpass can help you better. It might be a good idea to put this in your sig. This way when I am browsing the forum I can see if any servers are in trouble, even if you aren't in the forum.
Put this code into a text file, name it serverload.php and upload to your site anywhere you'd like. Then insert http://domain.com/serverload.php as an image source!
Another explanation from TomK:
[When you edit your signature] click the icon to "insert image" (to the right of insert email) and paste the file name there.
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 and set more image and font details */
$im = imageCreate(80,15);
$width = imagesx($im);
$height = imagesy($im);
$textcolor = imagecolorallocate($im, 0, 0, 0);
$textcolor2 = imagecolorallocate($im, 255,255,255);
$fillcolor1 = imagecolorallocate($im, 255,255,255);
$fillcolor2 = imagecolorallocate($im, 255,85,0);
$metercolor = imagecolorallocate($im, 0,240,0);
$bordercolor = imagecolorallocate($im, 0,0,0);
$bordercolor2 = imagecolorallocate($im, 40,40,40);
$textWidth = imagefontwidth($font) * strlen( $str );
$textHeight = imagefontheight($font);
/* get server load */
if (file_exists("/proc/loadavg") == true)
{
$fp = @fopen("/proc/loadavg", "r");
if (empty($fp) == false)
{
$loadavg = explode(" ", fread($fp, 6));
fclose($fp);
$loadav = substr($loadavg[0], 0, 4); // we don't want to many digits or it will overlap the meter
}
else
{
$loadav = "error";
}
}
else
{
$loadav = "error";
}
header("Content-type: image/gif");
$xLoc = 23;
$yLoc = 0;
/* over lap background image from the right with a white rectangle */
imagefilledrectangle ( $im, 0 ,0, $width, $height, $fillcolor1 );
imagefilledrectangle ( $im, 0 ,0, $width/4, $height, $fillcolor2 );
imagerectangle ( $im, 0,0, $width -1, $height-1, $bordercolor );
imagestring($im, 4, 4, $yLoc-1, "SL", $textcolor2);
imagestring($im,2, $xLoc, $yLoc, $loadav, $textcolor);
/* do meter bar */
if ($loadav != "error") {
$limit = 20; //this is the upper limit of the range of server load values... adjust to your server
$percent = ($loadav * 100) /$limit;
$meterwidth = ($percent / 100) * 28;
if ($meterwidth > $limit)
$meterwidth = $limit;
imagefilledrectangle ( $im, 48 ,4, 48 + $meterwidth, $height-6, $metercolor );
imagerectangle ( $im, 48,4, 76, $height-6, $bordercolor2 );
}
/* output gif image to browser */
imageGIF($im);
imagedestroy($im);
?>
|