From ad9087316a36c4149f0c39b255ef3eac166e5aac Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 27 Sep 2022 13:53:52 -0600 Subject: [PATCH] Fix a division by zero error. Add better support for BSD --- app/system/resources/dashboard/system_cpu_status.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/system/resources/dashboard/system_cpu_status.php b/app/system/resources/dashboard/system_cpu_status.php index 05601e11a8..933de337be 100644 --- a/app/system/resources/dashboard/system_cpu_status.php +++ b/app/system/resources/dashboard/system_cpu_status.php @@ -27,18 +27,22 @@ $row_style["1"] = "row_style1"; //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'); $percent_cpu = 0; foreach (explode("\n", $result) as $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')) { $result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); $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); //uptime