Remove CPU chart from system_status.php (#6153)

This commit is contained in:
AlexC 2021-11-23 18:35:11 -07:00 committed by GitHub
parent 588a9e32e0
commit 78427ee78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 97 deletions

View File

@ -25,19 +25,6 @@
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//cpu usage
if (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; }
}
$result = trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
$cores = count(explode("\n", $result));
if ($percent_cpu > 1) { $percent_cpu = $percent_cpu / $cores; }
$percent_cpu = round($percent_cpu, 2);
}
//disk usage
if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') {
$tmp = shell_exec("df /home 2>&1");
@ -49,86 +36,28 @@
}
if ($percent_disk_usage != '') {
//add half doughnut charts
//add half doughnut chart
?>
<div style='display: flex; flex-wrap: wrap; justify-content: center; padding-bottom: 8px'>
<div style='width: 175px; height: 175px; margin: 0 auto;'><canvas id='cpu_usage_chart'></canvas></div>
<div style='width: 175px; height: 175px; margin: 0 auto;'><canvas id='disk_usage_chart'></canvas></div>
<div style='width: 175px; height: 175px;'><canvas id='system_status_chart'></canvas></div>
</div>
<script>
var cpu_usage_chart_context = document.getElementById('cpu_usage_chart').getContext('2d');
var system_status_chart_context = document.getElementById('system_status_chart').getContext('2d');
var cpu_usage_chart_background_color;
if ('<?php echo $percent_cpu; ?>' <= 50) {
cpu_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['cpu_usage_chart_main_background_color'][0]; ?>';
} else if ('<?php echo $percent_cpu; ?>' <= 70 && '<?php echo $percent_cpu; ?>' > 50) {
cpu_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['cpu_usage_chart_main_background_color'][1]; ?>';
} else if ('<?php echo $percent_cpu; ?>' > 70) {
cpu_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['cpu_usage_chart_main_background_color'][2]; ?>';
}
const cpu_usage_chart_data = {
datasets: [{
data: ['<?php echo $percent_cpu; ?>', 100 - '<?php echo $percent_cpu; ?>'],
backgroundColor: [
cpu_usage_chart_background_color,
'<?php echo $_SESSION['dashboard']['cpu_usage_chart_sub_background_color']['text']; ?>'
],
borderColor: '<?php echo $_SESSION['dashboard']['cpu_usage_chart_border_color']['text']; ?>',
borderWidth: '<?php echo $_SESSION['dashboard']['cpu_usage_chart_border_width']['text']; ?>',
cutout: chart_cutout
}]
};
const cpu_usage_chart_config = {
type: 'doughnut',
data: cpu_usage_chart_data,
options: {
responsive: true,
maintainAspectRatio: false,
circumference: 180,
rotation: 270,
plugins: {
chart_counter_2: {
chart_text: '<?php echo $percent_cpu; ?>'
},
legend: {
display: false,
},
tooltip: {
yAlign: 'bottom',
displayColors: false,
},
title: {
display: true,
text: '<?php echo $text['label-processor_usage']; ?>'
}
}
},
plugins: [chart_counter_2],
};
const cpu_usage_chart = new Chart(
cpu_usage_chart_context,
cpu_usage_chart_config
);
var disk_usage_chart_context = document.getElementById('disk_usage_chart').getContext('2d');
var disk_usage_chart_background_color;
var system_status_chart_background_color;
if ('<?php echo $percent_disk_usage; ?>' < 60) {
disk_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][0]; ?>';
system_status_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][0]; ?>';
} else if ('<?php echo $percent_disk_usage; ?>' < 80 && '<?php echo $percent_disk_usage; ?>' > 60) {
disk_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][1]; ?>';
system_status_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][1]; ?>';
} else if ('<?php echo $percent_disk_usage; ?>' >= 80) {
disk_usage_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][2]; ?>';
system_status_chart_background_color = '<?php echo $_SESSION['dashboard']['disk_usage_chart_main_background_color'][2]; ?>';
}
const disk_usage_chart_data = {
const system_status_chart_data = {
datasets: [{
data: ['<?php echo $percent_disk_usage; ?>', 100 - '<?php echo $percent_disk_usage; ?>'],
backgroundColor: [disk_usage_chart_background_color,
backgroundColor: [system_status_chart_background_color,
'<?php echo $_SESSION['dashboard']['disk_usage_chart_sub_background_color']['text']; ?>'],
borderColor: '<?php echo $_SESSION['dashboard']['disk_usage_chart_border_color']['text']; ?>',
borderWidth: '<?php echo $_SESSION['dashboard']['disk_usage_chart_border_width']['text']; ?>',
@ -136,9 +65,9 @@
}]
};
const disk_usage_chart_config = {
const system_status_chart_config = {
type: 'doughnut',
data: disk_usage_chart_data,
data: system_status_chart_data,
options: {
responsive: true,
maintainAspectRatio: false,
@ -160,16 +89,16 @@
plugins: [chart_counter_2],
};
const disk_usage_chart = new Chart(
disk_usage_chart_context,
disk_usage_chart_config
const system_status_chart = new Chart(
system_status_chart_context,
system_status_chart_config
);
</script>
<?php
}
}
echo "<div class='hud_details' id='hud_system_status_details'>";
echo "<div class='hud_details hud_box' id='hud_system_status_details'>";
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr>\n";
echo "<th class='hud_heading' width='50%'>".$text['label-item']."</th>\n";
@ -245,17 +174,6 @@
}
}
//cpu usage
if (stristr(PHP_OS, 'Linux')) {
if ($percent_cpu != '') {
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' style='text-align: right;'>".$percent_cpu."%</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
}
//db connections
switch ($db_type) {
case 'pgsql':