} sleep(1); $time2 = getStat($_statPath); $delta = array(); foreach ($time1 as $k => $v) { $delta[$k] = $time2[$k] - $v; } $deltaTotal = array_sum($delta); $percentages = array(); foreach ($delta as $k => $v) { $percentages[$k] = @round($v / $deltaTotal * 100, 2); } return $percentages; } $cpu_string = ''; if (($cpu = getCpuUsage()) === -1) { $cpu_string = -1; } else { $cpulast = 100 - $cpu['idle']; $cpu_string .= lang(136) . ": <span id='cpuload'>" . round($cpulast, "0") . "</span>%<br />"; if (extension_loaded('gd') && function_exists('gd_info')) { $cpu_string .= '<img src="' . CLASS_DIR . 'bar.php?rating=' . round($cpulast, "2") . '" border="0" name="cpupercent" id="cpupercent" alt="" />'; } $cpu_string .= '<br />'; } } elseif ($os == "nocpu") { $cpu_string = ''; } else { $cpu_string = lang(136) . '<br />'; $cpu_string .= lang(136) . ": " . lang(137) . "<br />"; }
foreach ($time1 as $k => $v) { $delta[$k] = $time2[$k] - $v; } $deltaTotal = array_sum($delta); $percentages = array(); foreach ($delta as $k => $v) { $percentages[$k] = @round($v / $deltaTotal * 100, 2); } return $percentages; } else { return $msge; //return false; } } //--end getCpuUsage $cpu = getCpuUsage(); //if($cpu!==false){ if (is_array($cpu)) { if ($options["CpuLoadFormat"] == "percent") { $cpulast = $cpu ? 100 - $cpu['idle'] : 0; $cpu_string[0] = "CPU :: " . color_cpu(round($cpulast, "0")) . "%"; } else { $stats = @exec('uptime'); if (!$stats) { $stats = @shell_exec('uptime'); } preg_match('/averages?: ([0-9\\.]+),[\\s]+([0-9\\.]+),[\\s]+([0-9\\.]+)/', $stats, $regs); $cpulast = $regs[1]; $cpu_string[0] = "CPU :: " . color_cpu($cpulast); } $alert_sloadhigh = $options["limit_cpuload"] && $cpulast >= $options["ServerLoadAllowed"];
function makeCpuBars() { printBar(getCpuUsage(), "Usage"); }
} } else { $first = 0; } } return $cores; } /* compares two information snapshots and returns the cpu percentage */ function getCpuUsage($stat1, $stat2) { if (count($stat1) !== count($stat2)) { return; } for ($i = 0; $i < count($stat1); $i++) { $diff_idle[$i] = $stat2[$i]['idle'] - $stat1[$i]['idle']; $diff_total[$i] = $stat2[$i]['total'] - $stat1[$i]['total']; $DU = round(1000 * ($diff_total[$i] - $diff_idle[$i]) / $diff_total[$i] / 10, 2); $diff_usage[$i] = $DU > 100 ? 100 : $DU; } return $diff_usage; } $stat1 = getStat(); sleep(1); $stat2 = getStat(); $cores = getCpuUsage($stat1, $stat2); $nocpushow = "0"; } elseif ($os == "nocpu") { $nocpushow = "1"; } else { $nocpushow = "1"; }