News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[Depreciated]

Started by Depreciated, August 09, 2010, 08:02:51 PM

Previous topic - Next topic

Depreciated

Link to the mod


High Server Load Warning v2.5.2
~{By PaulpBaker}~

Link to Mod | My Mods | Support Topic

Compatibility
SMF 2.0

Description
Mod to display a message at the top right of your site that reads 'High server load detected' to warn people that the site might be running a little slow.

Default setting = A load of 3.00

Also has an option in admin settings to enable/disable the mod and change the load amount.

Have some suggestions to make this mod better? Please let me know in the support topic.

Notes
This is for Linux based servers ONLY!

Installation
Any previous versions of this mod MUST be uninstalled BEFORE installing this version.

Install the package on the SMF Default 'Curve' Theme ONLY. Other themes will need manual edits.

Useful Links
SMF Package Parser
Manual Installation Of Mods
How Do I Modify Files?

Support
Please use the modification thread for support with this modification.
(Please don't ask me to do the edits for you)

Changelog
v2.5.2 - 2nd September 2016: Updated to make compatible with SMF 2.0.11
v2.5.1 - 20th January 2011: Fixed a small CSS bug
v2.5 - 20th August 2010: Selectable 'load' amount option added to admin settings (Default is 3.00)
v2.2 - 13th August 2010: SMF v1.1.x Admin Settings
v2.1 - 13th August 2010: Initial SMF v1.1.x Support
v2.0 - 8th August 2010: Added admin options to enable/disable mod.
v1.0 - 27th July 2010: Initial Version

flapjack

excellent idea! can you tell us how it actually works?

Depreciated

wow interest in this mod in 5mins? excellent!! :)

but in short this uses the linux command 'sys_getloadavg()' to get the load of the server and is set to a default of 3 and can be changed if you wish (will have an admin option in v1.2 of the mod) and then shows a warning if it's the same or above of the set value and if it is it'll display the floating html/javascript warning

flapjack

neat :) thanks for the answer
I assume this is a standard command, and is not being restricted somehow by providers?

Depreciated

i'm not totally sure as i've only tested this on my own linux dedicated server and simply can't test it on all hosts but some right restrict it but i'm guessing 99% won't

Depreciated

if anyone can help with adding a selectable 'load' amount option in admin settings i'd be very grateful :)

Rafferty

I cant find anywhere in Admin to enable/disable, where is it?
Don't Follow me I got No Idea what I'm Doing

Depreciated

Quote from: Rafferty on August 13, 2010, 07:50:09 AM
I cant find anywhere in Admin to enable/disable, where is it?

Administration Center > Configuration > Modification Settings > Miscellaneous

'Enable High Server Load Warning Mod'

nend

After reading this post I though this would be a good idea to have in my chat system. So I have been building on your idea and been adding compatibility. Untested though my function, I think I have windows support by using PHP's passthru function to execute a Windows OS command and older PHP support by loading the loadavg file or if not available executing a shell command.

Dzonny

Great mod. Is there a chanse to port this for 1.1.11 versions?
I can help with adding to template if this can be done. :)

Depreciated

Quote from: Dzonny on August 13, 2010, 03:39:59 PM
Great mod. Is there a chanse to port this for 1.1.11 versions?
I can help with adding to template if this can be done. :)

Sure will port this to v1.1.x but I'm not aure how to so the admin option for v1.1.x :/

Depreciated

there we go support for smf v1.1.x but without the admin enable/disable option as i'm not sure how to do that on smf v1.1.x ;)

Dzonny

Quote from: PaulpBaker on August 13, 2010, 04:03:58 PM
there we go support for smf v1.1.x but without the admin enable/disable option as i'm not sure how to do that on smf v1.1.x ;)
Wow, that was quick :) Thanks.

Btw, u can add admin option in Sources/ModSettings.php

Depreciated

#13
Quote from: Dzonny on August 13, 2010, 04:16:03 PM
Quote from: PaulpBaker on August 13, 2010, 04:03:58 PM
there we go support for smf v1.1.x but without the admin enable/disable option as i'm not sure how to do that on smf v1.1.x ;)
Wow, that was quick :) Thanks.

Btw, u can add admin option in Sources/ModSettings.php

oh right i didn't know that was on v1.1.x as i thonut it was v2.x only :P

Depreciated

right v2.2 of this mod is out with full SMF v1.1.x support including the admin settings :)


nend

#16
Well don't know if I am going to implement this for 2-SI Chat but I have finished my load check script. This one will check PHP versions that support sys_getloadavg, lower versions of PHP that do not support this function and windows servers with PHP installed.

Note on Windows systems I could only get one load average so I went ahead and use the one load average for all three. Also I checked the windows server part of the script by using my command prompt and copying the output to a test script. It seems to work well but I do not have a windows server to test on.

$cpu[0] = load average 1
$cpu[2] = load average 2
$cpu[3] = load average 3

Your free to use any of this code for you mod, hope it will be useful.

if (function_exists('sys_getloadavg')) {
$cpu = sys_getloadavg();
} else if (!function_exists('sys_getloadavg') && !stristr(php_os, 'WIN')) {
if (file_exists('/proc/loadavg')) {
$cpu = explode(chr(32),file_get_contents('/proc/loadavg'));
} else {
$cpu = array_map("trim",explode(",",substr(strrchr(shell_exec("uptime"),":"),1)));
}
} else if (stristr(php_os, 'WIN')) {
ob_start();
passthru('typeperf -sc 1 "\processor(_total)\% processor time"',$status);
$content = ob_get_contents();
ob_end_clean();
if ($status === 0) {
if (preg_match("/\,\"([0-9]+\.[0-9]+)\"/",$content,$load)) {
$cpu[0] = $load[1];
$cpu[1] = $load[1];
$cpu[2] = $load[1];
}
}
}

Depreciated

wow that's out of my league lol wouldn't know what to do with it :P

nend

Not too hard.

Checks if sys_getloadavg exist and if it does cpu equals sys_getloadavg().
   if (function_exists('sys_getloadavg')) {
      $cpu = sys_getloadavg();

If no function sys_getloadavg(older versions of php) and server os is not windows
   } else if (!function_exists('sys_getloadavg') && !stristr(php_os, 'WIN')) {
If the loadavg file exist load it else run a shell command to get the load average.
      if (file_exists('/proc/loadavg')) {
         $cpu = explode(chr(32),file_get_contents('/proc/loadavg'));
      } else {
         $cpu = array_map("trim",explode(",",substr(strrchr(shell_exec("uptime"),":"),1)));
      }

Else if the server is windows Use PHP's passthru function to execute a windows os command to get the load average of the machine.
   } else if (stristr(php_os, 'WIN')) {
      ob_start();
      passthru('typeperf -sc 1 "\processor(_total)\% processor time"',$status);
      $content = ob_get_contents();
      ob_end_clean();
      if ($status === 0) {
         if (preg_match("/\,\"([0-9]+\.[0-9]+)\"/",$content,$load)) {
            $cpu[0] = $load[1];
            $cpu[1] = $load[1];
            $cpu[2] = $load[1];
         }
      }
   }


Hope that helps you understand the script a little. After that part is ran, you can run something like this.


if($modSettings['Check_load'] && $cpu[0] > $modSettings['max_load']) {
echo 'Server has reached max load setting';
}


This is how it is used in my mod.

if ($modSettings['2sichat_load_chk']) {
doLoadCHK();
}
function doLoadCHK() {

global $modSettings;

if (function_exists('sys_getloadavg')) {
$cpu = sys_getloadavg();
} else if (!function_exists('sys_getloadavg') && !stristr(php_os, 'WIN')) {
if (file_exists('/proc/loadavg')) {
$cpu = explode(chr(32),file_get_contents('/proc/loadavg'));
} else {
$cpu = array_map("trim",explode(",",substr(strrchr(shell_exec("uptime"),":"),1)));
}
} else if (stristr(php_os, 'WIN')) {
ob_start();
passthru('typeperf -sc 1 "\processor(_total)\% processor time"',$status);
$content = ob_get_contents();
ob_end_clean();
if ($status === 0) {
if (preg_match("/\,\"([0-9]+\.[0-9]+)\"/",$content,$load)) {
$cpu[0] = $load[1];
$cpu[1] = $load[1];
$cpu[2] = $load[1];
}
}
}

if ($cpu[0] && $cpu[0] > $modSettings['2sichat_max_load'] || $cpu[1] && $cpu[1] > $modSettings['2sichat_max_load'] || $cpu[2] && $cpu[2] > $modSettings['2sichat_max_load']) {
      if ($modSettings['2sichat_load_dis_chat']) {die();}
      if ($modSettings['2sichat_load_dis_bar']) {$modSettings['2sichat_dis_bar'] = 1;}
      if ($modSettings['2sichat_load_dis_list']) {$modSettings['2sichat_dis_list'] = 1;}
}
}

khadhafi

G8... thanks for this great mods.
Can u add some counter of how many percent again till the server will overload, adding a little counter system maybe? So we can prepare if this will happend.

Sory for my bad english Bro  ;)

Advertisement: