/** * Perform checks to see if there is enough server capacity to run a task. * * @param $threshold Pass in a threshold to test against - optional * The threshold value must be in [0..1] * 0: the server is completely idle * 1: is fully loaded * @return bool * If the server is Windows, return false (bypass this feature) */ function server_busy($threshold = false) { // Get current server load information - code from: // http://www.php.net//manual/en/function.sys-getloadavg.php#107243 // For Windows server users you can uncomment the following to try and access server load (experimental - use at own risk) if (stristr(PHP_OS, 'win')) { // $wmi = new COM("Winmgmts://"); // $server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor"); // $cpu_num = 0; // $load_total = 0; // foreach ($server as $cpu) { // $cpu_num++; // $load_total += $cpu->loadpercentage; // } // $load = round(($load_total / $cpu_num), 2); return false; } else { $sys_load = sys_getloadavg(); $load = $sys_load[0] / num_cpus(); } $threshold = $threshold ? $threshold : '0.5'; // TODO: find out a good base number if ($load > $threshold) { return true; } return false; }
} elseif ($storage <= "25%") { $storageL = "danger"; $storageTC = "black"; } elseif ($storage <= "50%") { $storageL = "warning"; } $array['hdd'] = '<div class="progress progress-striped active"> <div class="progress-bar progress-bar-' . $storageL . '" role="progressbar" style="width: ' . $storage . '; color: ' . $storageTC . ';">' . $storage . '</div> </div>'; // CPU Load $cpuUsage = ""; exec('ps -aux', $processes); foreach ($processes as $process) { $cols = split(' ', ereg_replace(' +', ' ', $process)); if (strpos($cols[2], '.') > -1) { $cpuUsage += floatval($cols[2]); } } $cpuUsage = $cpuUsage / num_cpus() . PHP_EOL; $cpuUsage = number_format((double) $cpuUsage, 2, '.', ''); $cpuUsage = $cpuUsage . '%'; //$array['load'] = $cpuUsage; $loadavg = sys_getloadavg(); $loadavg = $loadavg[0]; $loadavg = number_format((double) $loadavg, 2, '.', ''); $array['load'] = $loadavg; // If the server is online $array['online'] = '<div class="progress"> <div class="progress-bar progress-bar-success" role="progressbar" style="width: 100%;"><small>Up</small></div> </div>'; echo json_encode($array);
$ping_ip = $config['network_details']['ping_ip']; // Weather $weather_always_display = $config['weather']['weather_always_display']; $weather_lat = $config['weather']['weather_lat']; $weather_long = $config['weather']['weather_long']; $weather_name = $config['weather']['weather_name']; $forecast_api = $config['weather']['forecast_api']; $weather_units = $config['weather']['weather_units']; // Misc //$trakt_username = $config['misc']['trakt_username']; //$trakt_api_key = $config['misc']['trakt_api_key']; //$trakt_redirect_url = $config['misc']['trakt_redirect_url']; if (isset($config['misc']['cpu_cores'])) { $cpu_cores = $config['misc']['cpu_cores']; } else { $cpu_cores = num_cpus(); } // storage $volume_names[] = $config['storage']['volume_name']; $volume_paths[] = $config['storage']['volume_path']; //This is a new attempt at using objects to track different services /* global $services; function add_service($instances) { global $services; foreach ($instances as $instance) { $temp_object = new service(array_values($instance)[0],array_values($instance)[1],array_values($instance)[2],array_values($instance)[3]); $services[] = $temp_object; }
function server_load_percent() { return round(server_load() / num_cpus() * 100, 0); }