Showing server load
Posted: Thu Apr 15, 2004 10:18 pm
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.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
The value of Load: is what I'm trying to get.[ Time : 0.091s | 7 Queries | GZIP : Off | Load : 0.13 ]
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 ]
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>";
}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
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;
?>o Requirements
Apache with Extended Status and /server-status enabled.