View Single Post
Old February 1st, 2007, 6:34 AM   #1 (permalink)
Kayla
Searcher
Surpass Staff
 
Kayla's Avatar
 
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($im000);
$textcolor2 imagecolorallocate($im255,255,255);
$fillcolor1 imagecolorallocate($im255,255,255);
$fillcolor2 imagecolorallocate($im255,85,0);
$metercolor imagecolorallocate($im0,240,0);
$bordercolor imagecolorallocate($im0,0,0);
$bordercolor2 imagecolorallocate($im40,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($fp6));
                
fclose($fp);
                
$loadav substr($loadavg[0], 04);  // 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$width$height$fillcolor1 );
imagefilledrectangle $im,0$width/4$height$fillcolor2 );
imagerectangle $im0,0$width -1$height-1$bordercolor );
imagestring($im44$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 $im48 ,448 $meterwidth$height-6$metercolor );
    
imagerectangle $im48,476$height-6$bordercolor2 );
}
/* output gif image to browser */
imageGIF($im);
imagedestroy($im);
?>
__________________
Follow Surpass on Twitter and Facebook
Check out interesting finds on the Surpass Blog
.... it's coming.


Kayla is offline   Reply With Quote
These users thank Kayla for this great post!
2BitWannabe (February 7th, 2007), braincracking (September 10th, 2007), Brandonnn (February 1st, 2007), ceo (November 4th, 2007), Cøbra (March 5th, 2007), DewKnight (February 1st, 2007), Edwin (February 1st, 2007), Gaia (February 1st, 2007), ice2cu (January 20th, 2008), JadedSouls (January 10th, 2008), Kya (August 19th, 2007), lovetrick (September 19th, 2007), lucifer.dejos (February 28th, 2007), musicman2059 (February 6th, 2007), newbees (February 9th, 2007), oracleredux (February 9th, 2007), roxana (November 20th, 2007), Roxy (December 20th, 2007), Smo_Bob (September 20th, 2007), Zeggy (December 20th, 2007), ~ K ~ (August 26th, 2007)