Add CPU cores and load average.

This commit is contained in:
FusionPBX
2021-11-23 23:39:43 -07:00
committed by GitHub
parent 39ffbda8d5
commit 2a10d49b6d
@@ -16,28 +16,36 @@
//add multi-lingual support //add multi-lingual support
$language = new text; $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 "<div class='hud_box'>\n"; echo "<div class='hud_box'>\n";
//set the row style class names
$c = 0; $c = 0;
$row_style["0"] = "row_style0"; $row_style["0"] = "row_style0";
$row_style["1"] = "row_style1"; $row_style["1"] = "row_style1";
//cpu usage //get the CPU details
if (stristr(PHP_OS, 'Linux')) { if (PHP_OS == 'FreeBSD' || 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, 'Linux')) {
$result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); $result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
$cores = count(explode("\n", $result)); $cpu_cores = count(explode("\n", $result));
if ($percent_cpu > 1) { $percent_cpu = $percent_cpu / $cores; }
$percent_cpu = round($percent_cpu, 2);
} }
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
?> ?>
@@ -91,7 +99,7 @@
}, },
title: { title: {
display: true, display: true,
text: '<?php echo $text['label-processor_usage']; ?>' text: '<?php echo $text['label-cpu_usage']; ?>'
} }
} }
}, },
@@ -103,7 +111,10 @@
system_cpu_status_chart_config system_cpu_status_chart_config
); );
</script> </script>
<?php <?php
//show the content
echo "<div class='hud_details hud_box' id='hud_system_cpu_status_details'>"; echo "<div class='hud_details hud_box' id='hud_system_cpu_status_details'>";
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n"; echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr>\n"; echo "<tr>\n";
@@ -111,15 +122,40 @@
echo "<th class='hud_heading' style='text-align: right;'>".$text['label-value']."</th>\n"; echo "<th class='hud_heading' style='text-align: right;'>".$text['label-value']."</th>\n";
echo "</tr>\n"; echo "</tr>\n";
//cpu usage if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') {
if (stristr(PHP_OS, 'Linux')) {
if ($percent_cpu != '') { if ($percent_cpu != '') {
echo "<tr class='tr_link_void'>\n"; echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-processor_usage']."</td>\n"; echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-cpu_usage']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$percent_cpu."%</td>\n"; echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$percent_cpu."%</td>\n";
echo "</tr>\n"; echo "</tr>\n";
$c = ($c) ? 0 : 1; $c = ($c) ? 0 : 1;
} }
if ($cpu_cores != '') {
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-cpu_cores']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$cpu_cores."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-load_average']." (1)</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$load_average[0]."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-load_average']." (5)</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$load_average[1]."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-load_average']." (15)</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$load_average[2]."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
} }
echo "</table>\n"; echo "</table>\n";
@@ -128,4 +164,5 @@
echo "<span class='hud_expander' onclick=\"$('#hud_system_cpu_status_details').slideToggle('fast');\"><span class='fas fa-ellipsis-h'></span></span>"; echo "<span class='hud_expander' onclick=\"$('#hud_system_cpu_status_details').slideToggle('fast');\"><span class='fas fa-ellipsis-h'></span></span>";
echo "</div>\n"; echo "</div>\n";
?> ?>