• 0

Site Load Average Script


Question

I was wondering if anyone could throw something together like a Site Load script I saw

on DSLReports.

(www.dslreports.com - on topbar on far right)

If anyone can make a PHP or Perl Script just like that, i'm willing to float $10 to them.

Thanks!

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

i assume that u can make a script using php by just dividing the number of current visitors (within, say, 10 mins or so) by the total number u believe the server can support (say 100 users at the same time... just estimate this number) and just display a different image depending upon the percentage of users currently online

Link to comment
Share on other sites

  • 0

one sec...

$uptime = @exec( "uptime" );
preg_match( "/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs );

Access the avgs like: print $avgs[1];. Indices 1-3 will have the uptime stats for 1 minute, 10 minutes and 15 minutes.

Paypal $10 to timdorr&timdorr,com :)

Link to comment
Share on other sites

  • 0

Timdor, need it to do this, but I'm not very PHP Literate (am with BASIC though hehe)...

I need it to display certain text around certain averages, see below.

Can you fix this so it works right? Then you get your money.

<?php
$uptime = @exec( "uptime" );
preg_match( "/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs );
if ( $avgs < "0.50" ) {
	echo ( "<b>Very Low</b>" );
}
if ( $avgs < "0.79" ) {
	echo ( "<b>Lo</b>" );
} 
if ( $avgs > "0.80" ) {
	echo ( "<b>High</b>" );
} 

print $avgs[1];
?>

Link to comment
Share on other sites

  • 0

Actually, N/M. Here is the complete script - free for anyone's use.

Please give me and Timdor credit.

<?php

$uptime = @exec( "uptime" );

preg_match( "/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs );

echo ( "<a href=/misc/system_status.htm style=text-decoration: none>sysload:</a> " );

if ( $avgs[1] < "0.75" ) {

	echo ( "□□□□□□" );

	exit;

} 

if ( $avgs[1] < "1.00" ) {

	echo ( "<font color=green>■</font>□□□□□" );

	exit;

} 

if ( $avgs[1] < "2.00" ) {

	echo ( "<font color=green>■■</font>□□□□" );

	exit;

} 

if ( $avgs[1] < "3.00" ) {

	echo ( "<font color=green>■■<font color=yellow>■</font>□□□" );

	exit;

} 

if ( $avgs[1] < "4.00" ) {

	echo ( "<font color=green>■■<font color=yellow>■■</font>□□" );

	exit;

} 

if ( $avgs[1] < "6.00" ) {

	echo ( "<font color=green>■■<font color=yellow>■■<font color=red>■</font>□" );

	exit;

} 

if ( $avgs[1] < "7.00" ) {

	echo ( "<font color=green>■■<font color=yellow>■■<font color=red>■■</font>" );

	exit;

} 

if ( $avgs[1] > "8.00" ) {

	echo ( "<font color=red>OVERLOAD!!!</font>" );

	exit;

} 

?>

Link to comment
Share on other sites

  • 0

I dunno about the exit's though. They stop the script cold. So, if you want to have stuff after this, you can't. Here's how to fix that:

<?php

$uptime = @exec( "uptime" );
preg_match( "/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs );

echo ( "<a href=/misc/system_status.htm style=text-decoration: none>sysload:</a> " );

if ( $avgs[1] < "0.75" ) {
echo ( "□□□□□□" );
} 

if ( $avgs[1] < "1.00" && $avgs[1] >= "0.75" ) {
echo ( "<font color=green>■</font>□□□□□" );
} 

if ( $avgs[1] < "2.00" && $avgs[1] >= "1.00" ) {
echo ( "<font color=green>■■</font>□□□□" );
} 

if ( $avgs[1] < "3.00" && $avgs[1] >= "2.00" ) {
echo ( "<font color=green>■■<font color=yellow>■</font>□□□" );
} 

if ( $avgs[1] < "4.00" && $avgs[1] >= "3.00" ) {
echo ( "<font color=green>■■<font color=yellow>■■</font>□□" );
} 

if ( $avgs[1] < "6.00" && $avgs[1] >= "4.00" ) {
echo ( "<font color=green>■■<font color=yellow>■■<font color=red>■</font>□" );
}

if ( $avgs[1] < "7.00" && $avgs[1] >= "6.00" ) {
echo ( "<font color=green>■■<font color=yellow>■■<fontcolor=red>■■</font>" );
} 

if ( $avgs[1] > "8.00" && $avgs[1] >= "7.00" ) {
echo ( "<font color=red>OVERLOAD!!!</font>" );
} 
?>

Link to comment
Share on other sites

  • 0

Magoo - I wrote 95% of the script - the top line is his, all the rest was written by me, FYI... ;)

Link to comment
Share on other sites

  • 0
timdorr- how do you use that script to do what neowins done- just echo the current serverload- how would you do that?

Thanks

Tom, if you mean the server load averages in admin then yes just echo them

$uptime = @exec( "uptime" );

preg_match( "/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs );

echo ("Server Load Averages: <b>$avgs[1], $avgs[2], $avgs[3]</b>");

Link to comment
Share on other sites

  • 0

yeah - i searched php.net on exec() and it kinda gave the impression it was used to execute perl scripts- is there someting else other than the snip of code above that i need?

Link to comment
Share on other sites

  • 0

Maybe you're not allowed to execute commands.

script should be ok but you can try echo $uptime; to see if 'uptime' does anything

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.