Showing server load
Moderator: General Moderators
Showing server load
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.
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
If you look at the bottom of phpBB 2.2, you can see
The value of Load: is what I'm trying to get.[ Time : 0.091s | 7 Queries | GZIP : Off | Load : 0.13 ]
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
hmm interesting phice, do you know exactly how its calculated or what? i see no reference to this in the manual?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 seeThe value of Load: is what I'm trying to get.[ Time : 0.091s | 7 Queries | GZIP : Off | Load : 0.13 ]
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
):
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>";
}-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
: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?
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?
that cant be how PHPBB does it, because most hosting companies are linux, however this may prove usefulfeyd wrote:here is how to access the api in Windows machines.
You sure that is httpd server load, and not MySQL load? I'm thinking the later and likely by using either:
Not entirely sure tho, so dont bite my head of =)
Code: Select all
SHOW VARIABLES
SHOW STATUShttp://www.phpbb.com/phpBB/viewtopic.php?t=190156malcolmboston 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?
that cant be how PHPBB does it, because most hosting companies are linux, however this may prove usefulfeyd wrote:here is how to access the api in Windows machines.
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;
?>[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
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
