icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old September 6th, 2007, 7:27 PM   #1 (permalink)
Senior Member
Super #1
 
FredFredrickson's Avatar
 
Joined in Nov 2003
Lives in New Hampshire
1,254 posts
Gave thanks: 3
Thanked 27 times
Server Load Fun

So I decided to make my own server load image, and I started to wonder, why do we use this arbitrary number? According to the script Kayla released, the number is out of 20. Why do we use this numer that's otherwise arbitrary instead of using a percentage? Percentages are eaiser to use I'd say.

But then I noticed something. Math is wrong in the code released by Kayla. It assumes that the maximum server load could be 20, but then it generates the graph out of 28. Even worse, if the scale was 28, it's limited to 20, so the graph can never be more than 71% full.

So basically everybody's server load button is wrong.

Oh and also if it is out of 20, my button is correct - and better, it uses a percentage. YAY. Anybody want in?


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 
   
   Renovated:   Fred Fredrickson
   Website:     www.Fredrickville.com
   Changes:     Fixed percentages.
*/ 


/* get and set more image and font details */ 
$servername "SH105";
$maximumserverload 20//this is the upper limit of the range of server load values... adjust to your server 
$im imagecreatetruecolor(91,24); 

$width imagesx($im); 
$height imagesy($im); 
$textcolor imagecolorallocate($im2,61,88);
$textcolor2 imagecolorallocate($im255,255,255); 
$fillcolor1 imagecolorallocate($im195,202,214); 
$fillcolor2 imagecolorallocate($im2,61,88); 
$metercolor imagecolorallocate($im75,115,136); 
$bordercolor imagecolorallocate($im0,0,0);
$bordercolor2 imagecolorallocate($im255,255,255); 
$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 26
$yLoc 0
$loadperc round(($loadav $maximumserverload) * 1002);
if(!
strpos($loadperc"."))
{
$loadperc $loadperc ".00";
}
if(
substr($loadpercstrlen($loadperc) - 21) == ".")
{
$loadperc $loadperc "0";
}
if(
round(($loadav $maximumserverload) * 1002) == 100)
{
$loadperc "100";
}
/* over lap background image from the right with a white rectangle */ 
imagefilledrectangle $im,0$width$height$fillcolor1 ); 
imagefilledrectangle $im,0$width10$fillcolor2 ); 
imagerectangle $im0,0$width -1$height-1$bordercolor ); 

imagestring($im131"SERVER LOAD:" $servername$textcolor2); 
imagestring($im,2310$loadperc "%"$textcolor); 
$src ImageCreateFromJPEG("/home/fredric/public_html/arrow.jpg"); 

/* do meter bar */ 
if ($loadav != "error") { 
    
$limit $width - (4);   
    
$percent round(($loadav $maximumserverload) * 1002); 
    
$meterwidth = ((($percent 100) * (($width 4) - 40)) + 40);

    if (
$meterwidth $limit
        
$meterwidth $limit

    
imagefilledrectangle $im4014$meterwidth$height-5$metercolor ); 
    
imagerectangle $im4014$width - (4), $height-(5), $metercolor ); 

/* output gif image to browser */ 
imageGIF($im); 
imagedestroy($im); 
?>
__________________

Surmunity Special-Free Photos To Season Your Site/Blog, Code: fallatsurpass

Last edited by FredFredrickson; September 6th, 2007 at 7:33 PM.. Reason: I'm good at math
FredFredrickson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 7:39 PM   #2 (permalink)
minor deity
Super #1
 
Bigjohn's Avatar
 
Joined in Apr 2004
Lives in Georgia
Hosted on XEON
7,387 posts
Gave thanks: 28
Thanked 94 times
How are you determining the percentage and it's accuracy?
__________________
Proud to be a Surmunity Mod!
XEON PASS60 PASS61
Make a fundamental difference!
My Sites:
Curious about Brewing Beer? Join the community!
>>>>> Some Change is GOOD! Keep your paycheck! Support the Fair Tax
Get into an Art museum
Victorian London
It's your brain -ON WEB - mybrainhost.com (under development)
What SHOULD Government do? Much Less than it Does!
Bigjohn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 7:44 PM   #3 (permalink)
He shoots.. He scores!
Super #1
 
puckchaser's Avatar
 
Joined in Feb 2007
Lives in A room with no windows.
Hosted on SH110
1,448 posts
Gave thanks: 46
Thanked 140 times
Here goes...

He assumes,

$maximumserverload = 20

and

Then he gets the avg server load

$fp = fopen("/proc/loadavg", "r");

Then divides average over max

$loadperc = round(($loadav / $maximumserverload) * 100, 2);

He's got some fancy other code in there, but thats the gist of it.

I assume accuracy would depend on
(1) do you believe 20 is the max
(2) do you believe /proc/loadavg
__________________
SH110
puckchaser is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 7:45 PM   #4 (permalink)
Senior Member
Super #1
 
FredFredrickson's Avatar
 
Joined in Nov 2003
Lives in New Hampshire
1,254 posts
Gave thanks: 3
Thanked 27 times
According to the script, the max server load is 20, so we have a scale. However, the script used two different scales. but tried to show them on the same graph. Not sure which was right, if either. I'm assuming that the server load has a max.. ??
__________________

Surmunity Special-Free Photos To Season Your Site/Blog, Code: fallatsurpass
FredFredrickson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 7:59 PM   #5 (permalink)
Surpass Abuse Admin
Super #1
 
removed's Avatar
 
Joined in Mar 2005
Lives in Houston, TX
Hosted on NONE
7,797 posts
Gave thanks: 11
Thanked 278 times
Quote:
Originally Posted by FredFredrickson View Post
Not sure which was right, if either. I'm assuming that the server load has a max.. ??
Nope, it sure doesn't, though your server load image should be interesting if the server's load spikes to 300 from someone sending spam...
__________________
Unofficial IRC Channel: #surpass EFNet
Unofficial = No official support. Support requests can be submitted to our helpdesk.
removed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 8:01 PM   #6 (permalink)
Senior Member
Super #1
 
FredFredrickson's Avatar
 
Joined in Nov 2003
Lives in New Hampshire
1,254 posts
Gave thanks: 3
Thanked 27 times
hot damn! How is it calculated then? what a useless number
__________________

Surmunity Special-Free Photos To Season Your Site/Blog, Code: fallatsurpass
FredFredrickson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 8:04 PM   #7 (permalink)
4-8-15-16-23-42
Excelling Contributor
 
caseylee's Avatar
 
Joined in Jul 2007
Lives in Australia, turn left at America
Hosted on Luna & Nexus (dedicated)
779 posts
Gave thanks: 37
Thanked 29 times
My serverload button is prettier
__________________
caseylee is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 8:05 PM   #8 (permalink)
Surpass Abuse Admin
Super #1
 
removed's Avatar
 
Joined in Mar 2005
Lives in Houston, TX
Hosted on NONE
7,797 posts
Gave thanks: 11
Thanked 278 times
It has a Domo Kun in it! I'm sorry FredFredrickson, but caseylee wins...
__________________
Unofficial IRC Channel: #surpass EFNet
Unofficial = No official support. Support requests can be submitted to our helpdesk.
removed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 6th, 2007, 8:05 PM   #9 (permalink)
Senior Member
Super #1
 
FredFredrickson's Avatar
 
Joined in Nov 2003
Lives in New Hampshire
1,254 posts
Gave thanks: 3
Thanked 27 times
Ok, but seriously now, what's the point to the graph when you have an arbitrary number with no scale?
__________________

Surmunity Special-Free Photos To Season Your Site/Blog, Code: fallatsurpass
FredFredrickson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On