MyBB Community Forums

Full Version: Any Decent Server Load Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I been Googeling for ages for a simple server load script that shows the server load in percentages or even better in bars (green to red). When I google for it I get all this junk about website uptime scripts and monitor software but I just want a simple server load script.

Anyone know a good one?
I actually have a really good one I use, but unfortunately I don't have access to it right now. I posted it somewhere a while back so let me do some digging. Oh, and this is for a Linux based server right?
I can't find it, but depending on your server's security settings this should work:

<?php
$load = get_server_load();
echo "Server Load: $load";
?>

Of course because of the way Linux measures CPU load converting it into a percent or a bar is going to be subjective to what you consider it to mean. Some people would see 4.0 as 100% while others might view 10.0 as 100% but at the same time some companies consider 2.0 as being near 100%. I was once told to use 1 to represent one core, so a quad core CPU would be maxed out at 4.0, come to find out my quad core Xeon can handle 20.0+ without slowing down any processing.
Do you have root access/ssh access?
(2009-12-24, 07:40 AM)KuJoe Wrote: [ -> ]I actually have a really good one I use, but unfortunately I don't have access to it right now. I posted it somewhere a while back so let me do some digging. Oh, and this is for a Linux based server right?
I can't find it, but depending on your server's security settings this should work:

<?php
$load = get_server_load();
echo "Server Load: $load";
?>

Of course because of the way Linux measures CPU load converting it into a percent or a bar is going to be subjective to what you consider it to mean. Some people would see 4.0 as 100% while others might view 10.0 as 100% but at the same time some companies consider 2.0 as being near 100%. I was once told to use 1 to represent one core, so a quad core CPU would be maxed out at 4.0, come to find out my quad core Xeon can handle 20.0+ without slowing down any processing.

Yes its Linux. I dont really care what - what represents for my part it get be 1 bar for 20% for example. Please do give me the script when you got access to it Big Grin.

(2009-12-24, 08:22 AM)Mark.M Wrote: [ -> ]Do you have root access/ssh access?
SSH
I did get this:

http://winpulse.net/server.php

But the load is stated as:

Load: 0.13,0.18,0.17

What does that mean? Are those the load averages?
Yeah they are.
I used this for some of my scripts:
//GET SERVER LOADS
$loadresult = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
$load = "Server Load: $avgs[1]";
echo $load;
Download rapidleech script and reverse engineer from there.
Linux represents server load in that fashion: 0.00 I've yet to find a definite explaination of what it means but most people consider 1.00 to be 100%, but I have found that to be inaccurate based on real world usage and big companies such as cPanel consider 2.00 to be "high load" while MyBBoard has 5.00 as the default for considering "high load".

When you check you loads like that (uptime, top, get_server_load(), etc...) it will always read as #.## #.## #.## which translates to the average server load over 1, 5, and 15 minutes.

As for a bar or percentage, that will require some custom coding because as I said, Linux doesn't represent CPU load like that and I've never been about to find the formula for determining server load. The common representation of the formula is: Actual load = Total load(as shown in uptime) / no. of CPUs but as I said, I've encountered different experiences in real world environments.
Alright thanks Joe Smile

@PolarBear:

I got that script at the moment but I would like to see it into little bars or something like that Big Grin.
I just woke up and threw this together. Not sure if it will work or not though.
<?php
	$load = file_get_contents("/proc/loadavg");
        $load = explode(' ', $load);
	$users[0] = "Unavailable";
	$users[1] = "--";
	$loadnow = $load[0];
	$load15 = $load[1];
	$load30 = $load[2];
if ($loadnow <= 0.25) {
	$cpuload = "<img src=\"images\bar1.png\" />";
}
if ($loadnow > 0.25 && $loadnow <= 0.50) {
	$cpuload = "<img src=\"images\bar2.png\" />";
}
if ($loadnow > 0.50 && $loadnow <= 0.75) {
	$cpuload = "<img src=\"images\bar3.png\" />";
}
if ($loadnow > 0.75 && $loadnow <= 1) {
	$cpuload = "<img src=\"images\bar4.png\" />";
}
if ($loadnow > 1 && $loadnow <= 1.50) {
	$cpuload = "<img src=\"images\bar5.png\" />";
}
if ($loadnow > 1.50 && $loadnow <= 2.0) {
	$cpuload = "<img src=\"images\bar6.png\" />";
}
if ($loadnow > 2) {
	$cpuload = "<img src=\"images\bar7.png\" />";
}
	echo "<b>CPU Load:</b> <load>$cpuload</load>";
}
?>
Thanks I fixed some errors in the code and I got a access deinied to /proc/loadavg so I made my code into this:

<?php

    $users[0] = "Unavailable";
    $users[1] = "--";
    $loadnow = $load[0];
    $load15 = $load[1];
    $load30 = $load[2];
	
if ($loadnow <= 0.25) {
    $cpuload = "<img src=\"1.png\" />";
}
if ($loadnow > 0.25 && $loadnow <= 0.50) {
    $cpuload = "<img src=\"2.png\" />";
}
if ($loadnow > 0.50 && $loadnow <= 0.75) {
    $cpuload = "<img src=\"3.png\" />";
}
if ($loadnow > 0.75 && $loadnow <= 1) {
    $cpuload = "<img src=\"4.png\" />";
}
if ($loadnow > 1 && $loadnow <= 1.50) {
    $cpuload = "<img src=\"5.png\" />";
}
if ($loadnow > 1.50 && $loadnow <= 2.0) {
    $cpuload = "<img src=\"6.png\" />";
}
if ($loadnow > 2) {
    $cpuload = "<img src=\"7.png\" />";
}
    echo "<b>CPU Load:</b> <load>$cpuload</load>";


?>

It seems to work because it shows one part at the moment but I am not sure if it 100% works. I guess Ill have to wait to see the bars change Big Grin.
Pages: 1 2 3