Fix a division by zero error.

Add better support for BSD
This commit is contained in:
FusionPBX 2022-09-27 13:53:52 -06:00 committed by GitHub
parent c28dcab2ca
commit ad9087316a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -27,18 +27,22 @@
$row_style["1"] = "row_style1"; $row_style["1"] = "row_style1";
//get the CPU details //get the CPU details
if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') { if (stristr(PHP_OS, 'BSD') || stristr(PHP_OS, 'Linux')) {
$result = shell_exec('ps -A -o pcpu'); $result = shell_exec('ps -A -o pcpu');
$percent_cpu = 0; $percent_cpu = 0;
foreach (explode("\n", $result) as $value) { foreach (explode("\n", $result) as $value) {
if (is_numeric($value)) { $percent_cpu = $percent_cpu + $value; } if (is_numeric($value)) { $percent_cpu = $percent_cpu + $value; }
} }
if (stristr(PHP_OS, 'BSD')) {
$result = trim(shell_exec("dmesg | grep -i --max-count 1 CPUs | sed 's/[^0-9]*//g'"));
$cpu_cores = trim($result);
}
if (stristr(PHP_OS, 'Linux')) { if (stristr(PHP_OS, 'Linux')) {
$result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); $result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
$cpu_cores = count(explode("\n", $result)); $cpu_cores = count(explode("\n", $result));
} }
if ($percent_cpu > 1) { $percent_cpu = $percent_cpu / $cpu_cores; } if ($cpu_cores > 1) { $percent_cpu = $percent_cpu / $cpu_cores; }
$percent_cpu = round($percent_cpu, 2); $percent_cpu = round($percent_cpu, 2);
//uptime //uptime