Page 1 of 1

Showing server load

Posted: Thu Apr 15, 2004 10:18 pm
by phice
Can any of you guys help me with showing the server load? Is it possible to show it on Windows as well? Thanks very much.

Posted: Fri Apr 16, 2004 3:09 am
by vigge89
server load?

do you mean page generation time? :? :?:

Posted: Fri Apr 16, 2004 2:32 pm
by phice
Some pages have "Server Load: 0.12" or something to the similar.

If you look at the bottom of phpBB 2.2, you can see
[ Time : 0.091s | 7 Queries | GZIP : Off | Load : 0.13 ]
The value of Load: is what I'm trying to get.

Posted: Fri Apr 16, 2004 2:35 pm
by malcolmboston
phice wrote:Some pages have "Server Load: 0.12" or something to the similar.

If you look at the bottom of phpBB 2.2, you can see
[ Time : 0.091s | 7 Queries | GZIP : Off | Load : 0.13 ]
The value of Load: is what I'm trying to get.
hmm interesting phice, do you know exactly how its calculated or what? i see no reference to this in the manual?

Posted: Fri Apr 16, 2004 2:50 pm
by phice
That's what I'm asking..

I found somewhere that you read a directory for some oblivious file. The code follows (though doesnt work on my linux host, nor my windows box (duh ;)):

Code: Select all

if($fh = @fopen("/proc/loadavg", "r"))
           {
              $data = @fread($fh, 6);
              @fclose($fh);
              $load_avg = explode(" ", $data);
              $load_avg = trim($load_avg[0]);
           } else {
              $load_avg = "<font color="#FF0000">error</font>";
           }

Posted: Fri Apr 16, 2004 2:58 pm
by feyd
here is how to access the api in Windows machines.

Posted: Fri Apr 16, 2004 3:37 pm
by vigge89
so, what is the number rounded/counted by, cpu-usage or something?
sorry if you do not understand, can't come up with thw wird for it...

Posted: Sat Apr 17, 2004 1:47 pm
by malcolmboston
:BUMP:

this is a very interesting subject, does anyone know the answer?

phice, maybe you can shoot an e-mail of to the dev's of PHPBB asking them?
feyd wrote:here is how to access the api in Windows machines.
that cant be how PHPBB does it, because most hosting companies are linux, however this may prove useful

Posted: Sat Apr 17, 2004 3:00 pm
by JAM
You sure that is httpd server load, and not MySQL load? I'm thinking the later and likely by using either:

Code: Select all

SHOW VARIABLES
SHOW STATUS
Not entirely sure tho, so dont bite my head of =)

Posted: Sat Apr 17, 2004 3:27 pm
by phice
malcolmboston wrote::BUMP:

this is a very interesting subject, does anyone know the answer?

phice, maybe you can shoot an e-mail of to the dev's of PHPBB asking them?
feyd wrote:here is how to access the api in Windows machines.
that cant be how PHPBB does it, because most hosting companies are linux, however this may prove useful
http://www.phpbb.com/phpBB/viewtopic.php?t=190156

Posted: Sat Apr 17, 2004 4:55 pm
by JAM

Code: Select all

<?php
/*

Realtime Apache Bandwidth-Based Redirection
AKA *Very* Inexpensive Load Balancing
Copyright (C) 2002 Alex Moundalexis. All Rights Reserved.
Email: alexm at mail.rit.edu

o Purpose

  When hosting sites on-campus, the network guys get <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> when you
  consume large amounts of bandwidth. So to get them off my back, I
  wrote this to distribute extraneous load to other servers.

o License

  This script is licensed as freeware. Use it however you wish,
  so long as my contact information remains on the header. I
  provide it so that others may learn from it.

  This script is provided as is, without any warranty of usability.
  Use it at your own risk.

o Requirements

  Apache with Extended Status and /server-status enabled.
  PHP 4.0+

o Instructions

  Setup the variables here, and uncomment the method
  you want to use below. Piece of cake, really. It's a quick snippet
  that I found useful. It'd be easy to add a randomizing script to pick
  the mirror.

  As usual, all this crap is longer than the actual script. 

*/

$server = "127.0.0.1";            // Your server.
$maxband = "500000";            // Maximum Bandwidth before rollover in BYTES.
                    // 500000 is 500k, etc.
$mirror = "mirror.yoursite.com";    // The mirror server.

$handle = fopen ("http://$server/server-status?auto", "r");
while (!feof($handle)) {
     $buffer=fread($handle,4096);
}
fclose($handle);

/* Returns the following stuff...
Total Accesses: 22403
Total kBytes: 434115
CPULoad: .341125
Uptime: 612319
ReqPerSec: .0365871
BytesPerSec: 725.984
BytesPerReq: 19842.6
BusyServers: 3
IdleServers: 7
Scoreboard: _W_____KW_... etc etc etc
*/

list($th,$tb,$cpu,$uptime,$rs,$bs,$br,$busy,$idle,$scoreboard)= split ("\n", $buffer);

/* Additional things to parse... don't need them here, but they're available.
$th = ereg_replace(".*Total Accesses: ", "", $th);
$tb = ereg_replace(".*Total kBytes: ", "", $tb);
$cpu = ereg_replace(".*CPULoad: ", "", $cpu);
$uptime = ereg_replace(".*Uptime: ", "", $uptime);
$rs = ereg_replace(".*ReqPerSec: ", "", $rs);
$br = ereg_replace(".*BytesPerReq: ", "", $br);
*/

$bs = ereg_replace(".*BytesPerSec: ", "", $bs);

if ($bs > $maxband) {
  $location = "http://$mirror/$file";
} else {
  $location = "http://$server/$file";
}

// Test Method
echo "<p>$server limit is $maxband bytes. Current bandwidth is $bs.</p>";
echo "<p>Sending you to <b>$location</b>.</p>";

// Method 1: Send them directly to the file. Good for files.
// header("Location: $location");

// Method 2: Embed the path as text (in an IMG tag, etc).
// To use, where you'd stick the source, call PHP with the following code:
// readfile("http://path.com/to/load.php?sn=file");
// echo $location;

?>
(Googled 0.87 minutes... ;))

Posted: Sat Apr 17, 2004 5:02 pm
by vigge89
[quote=PHP]
Warning: fopen(http://127.0.0.1/server-status?auto): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in J:\Server\htdocs\test.php on line 45
[/quote]
doesn't seem to work for me :?

Posted: Sun Apr 18, 2004 2:54 am
by JAM
o Requirements

Apache with Extended Status and /server-status enabled.