From 2a10d49b6d3c48b56a5b68f110c2edda7627d3cb Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 23 Nov 2021 23:39:43 -0700 Subject: [PATCH] Add CPU cores and load average. --- .../resources/dashboard/system_cpu_status.php | 197 +++++++++++------- 1 file changed, 117 insertions(+), 80 deletions(-) diff --git a/app/system/resources/dashboard/system_cpu_status.php b/app/system/resources/dashboard/system_cpu_status.php index f4a07e86ca..84bd7e3844 100644 --- a/app/system/resources/dashboard/system_cpu_status.php +++ b/app/system/resources/dashboard/system_cpu_status.php @@ -16,94 +16,105 @@ //add multi-lingual support $language = new text; - $text = $language->get($_SESSION['domain']['language']['code'], 'core/user_settings'); + $text = $language->get($_SESSION['domain']['language']['code'], 'app/system'); -//system status +//system cpu status echo "
\n"; +//set the row style class names $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; - //cpu usage - if (stristr(PHP_OS, 'Linux')) { +//get the CPU details + if (PHP_OS == 'FreeBSD' || 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; } } - $result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); - $cores = count(explode("\n", $result)); - if ($percent_cpu > 1) { $percent_cpu = $percent_cpu / $cores; } + 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; } $percent_cpu = round($percent_cpu, 2); + + //uptime + $result = shell_exec('uptime'); + $load_average = sys_getloadavg(); + } +//add half doughnut chart + ?> +
+
+
- //add half doughnut chart - ?> -
-
-
- - - ' + } + } + }, + plugins: [chart_counter_2], + }; + + const system_cpu_status_chart = new Chart( + system_cpu_status_chart_context, + system_cpu_status_chart_config + ); + + +"; echo "\n"; echo "\n"; @@ -111,21 +122,47 @@ echo "\n"; echo "\n"; - //cpu usage - if (stristr(PHP_OS, 'Linux')) { - if ($percent_cpu != '') { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - $c = ($c) ? 0 : 1; - } + if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') { + if ($percent_cpu != '') { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $c = ($c) ? 0 : 1; } + if ($cpu_cores != '') { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $c = ($c) ? 0 : 1; + } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $c = ($c) ? 0 : 1; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $c = ($c) ? 0 : 1; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $c = ($c) ? 0 : 1; + } + echo "
".$text['label-value']."
\n"; echo "
"; $n++; echo ""; echo "\n"; + ?>