diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index bf0961bc..28a7bf96 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -456,4 +456,19 @@ $config['cookie']['secure'] = false; **/ $config['smarty']['cache'] = 0; $config['smarty']['cache_lifetime'] = 30; + +/** + * System load setting + * + * This will disable loading of some API calls in case the system + * loads exceeds the defined max setting. Useful to temporaily suspend + * live statistics on a server that is too busy to deal with requests. + * + * Options + * max = float, maximum system load + * + * Defaults: + * max = 10.0 + **/ +$config['system']['load']['max'] = 10.0; ?> diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 94541365..95d3b061 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -3,6 +3,14 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); +// System load check +if ($load = @sys_getloadavg()) { + if (isset($config['system']['load']['max']) && $load[0] > $config['system']['load']['max']) { + header('HTTP/1.1 503 Too busy, try again later'); + die('Server too busy. Please try again later.'); + } +} + // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);