fusionpbx/app/system/resources/dashboard/system_status.php

309 lines
10 KiB
PHP
Raw Normal View History

2021-11-10 02:42:14 +01:00
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
//check permisions
require_once "resources/check_auth.php";
if (permission_exists('xml_cdr_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'core/user_settings');
//system status
2021-11-10 07:16:50 +01:00
echo "<div class='hud_box'>\n";
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
$c = 0;
$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; }
2021-11-10 06:38:15 +01:00
}
2021-11-10 07:16:50 +01:00
$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);
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//disk usage
if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') {
$tmp = shell_exec("df /home 2>&1");
$tmp = explode("\n", $tmp);
$tmp = preg_replace('!\s+!', ' ', $tmp[1]); // multiple > single space
$tmp = explode(' ', $tmp);
foreach ($tmp as $stat) {
if (substr_count($stat, '%') > 0) { $percent_disk_usage = rtrim($stat,'%'); break; }
}
2021-11-10 02:42:14 +01:00
2021-11-12 20:58:04 +01:00
if ($percent_disk_usage != '') {
2021-11-12 20:56:19 +01:00
//add half doughnut charts
?>
<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>
<script>
var cpu_chart_background_color;
if ('<?php echo $percent_cpu; ?>' <= 50) {
cpu_chart_background_color = '#03c04a';
} else if ('<?php echo $percent_cpu; ?>' <= 70 && '<?php echo $percent_cpu; ?>' > 50) {
cpu_chart_background_color = '#ff9933';
} else if ('<?php echo $percent_cpu; ?>' > 70) {
cpu_chart_background_color = '#ea4c46';
}
const cpu_usage_data = {
datasets: [{
data: ['<?php echo $percent_cpu; ?>', 100 - '<?php echo $percent_cpu; ?>'],
backgroundColor: [cpu_chart_background_color, '#d4d4d4'],
borderColor: 'rgba(0,0,0,0)',
cutout: chart_cutout
}]
};
const cpu_usage_config = {
type: 'doughnut',
data: cpu_usage_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']; ?>'
}
2021-11-10 06:38:15 +01:00
}
2021-11-12 20:56:19 +01:00
},
plugins: [chart_counter_2],
};
const cpu_usage_chart = new Chart(
document.getElementById('cpu_usage_chart'),
cpu_usage_config
);
var disk_chart_background_color;
if ('<?php echo $percent_disk_usage; ?>' < 60) {
disk_chart_background_color = '#03c04a';
} else if ('<?php echo $percent_disk_usage; ?>' < 80 && '<?php echo $percent_disk_usage; ?>' > 60) {
disk_chart_background_color = '#ff9933';
} else if ('<?php echo $percent_disk_usage; ?>' >= 80) {
disk_chart_background_color = '#ea4c46';
}
const disk_chart_config = {
type: 'doughnut',
data: {
2021-11-10 07:16:50 +01:00
datasets: [{
2021-11-12 20:56:19 +01:00
data: ['<?php echo $percent_disk_usage; ?>', 100 - '<?php echo $percent_disk_usage; ?>'],
backgroundColor: [disk_chart_background_color, '#d4d4d4'],
borderColor: 'rgba(0,0,0,0)',
2021-11-10 07:16:50 +01:00
cutout: chart_cutout
}]
2021-11-12 20:56:19 +01:00
},
options: {
responsive: true,
maintainAspectRatio: false,
circumference: 180,
rotation: 270,
plugins: {
chart_counter_2: {
chart_text: '<?php echo $percent_disk_usage; ?>'
},
legend: {
display: false
},
title: {
2021-11-10 07:16:50 +01:00
display: true,
2021-11-12 20:56:19 +01:00
text: '<?php echo $text['label-disk_usage']; ?>'
2021-11-10 06:38:15 +01:00
}
2021-11-12 20:56:19 +01:00
}
},
plugins: [chart_counter_2],
};
const disk_usage_chart = new Chart(
document.getElementById('disk_usage_chart'),
disk_chart_config
);
</script>
<?php
2021-11-10 02:42:14 +01:00
}
2021-11-10 07:16:50 +01:00
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:40:24 +01:00
echo "<div class='hud_details' id='hud_system_status_details'>";
2021-11-10 07:16:50 +01:00
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";
echo "<th class='hud_heading' style='text-align: right;'>".$text['label-value']."</th>\n";
echo "</tr>\n";
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//pbx version
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".(isset($_SESSION['theme']['title']['text'])?$_SESSION['theme']['title']['text']:'FusionPBX')."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".software::version()."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//os uptime
if (stristr(PHP_OS, 'Linux')) {
unset($tmp);
$cut = shell_exec("/usr/bin/which cut");
$uptime = trim(shell_exec(escapeshellcmd($cut." -d. -f1 /proc/uptime")));
$tmp['y'] = floor($uptime/60/60/24/365);
$tmp['d'] = $uptime/60/60/24%365;
$tmp['h'] = $uptime/60/60%24;
$tmp['m'] = $uptime/60%60;
$tmp['s'] = $uptime%60;
$uptime = (($tmp['y'] != 0 && $tmp['y'] != '') ? $tmp['y'].'y ' : null);
$uptime .= (($tmp['d'] != 0 && $tmp['d'] != '') ? $tmp['d'].'d ' : null);
$uptime .= (($tmp['h'] != 0 && $tmp['h'] != '') ? $tmp['h'].'h ' : null);
$uptime .= (($tmp['m'] != 0 && $tmp['m'] != '') ? $tmp['m'].'m ' : null);
$uptime .= (($tmp['s'] != 0 && $tmp['s'] != '') ? $tmp['s'].'s' : null);
if ($uptime != '') {
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-system_uptime']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$uptime."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
2021-11-10 02:42:14 +01:00
}
2021-11-10 07:16:50 +01:00
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//memory usage (for available memory, use "free | awk 'FNR == 3 {print $4/($3+$4)*100}'" instead)
if (stristr(PHP_OS, 'Linux')) {
$free = shell_exec("/usr/bin/which free");
$awk = shell_exec("/usr/bin/which awk");
$percent_memory = round(shell_exec(escapeshellcmd($free." | ".$awk." 'FNR == 3 {print $3/($3+$4)*100}'")), 1);
if ($percent_memory != '') {
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-memory_usage']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$percent_memory."%</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
2021-11-10 02:42:14 +01:00
}
2021-11-10 07:16:50 +01:00
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//memory available
if (stristr(PHP_OS, 'Linux')) {
$result = trim(shell_exec('free -hw | grep \'Mem:\' | cut -d\' \' -f 55-64'));
if ($result != '') {
2021-11-10 02:42:14 +01:00
echo "<tr class='tr_link_void'>\n";
2021-11-10 07:16:50 +01:00
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-memory_available']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$result."</td>\n";
2021-11-10 02:42:14 +01:00
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
2021-11-10 07:16:50 +01:00
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//disk usage
if (stristr(PHP_OS, 'Linux')) {
//calculated above
if ($percent_disk_usage != '') {
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-disk_usage']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$percent_disk_usage."%</td>\n";
2021-11-10 02:42:14 +01:00
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
2021-11-10 07:16:50 +01:00
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
//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";
2021-11-10 02:42:14 +01:00
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
2021-11-10 07:16:50 +01:00
}
//db connections
switch ($db_type) {
case 'pgsql':
$sql = "select count(*) from pg_stat_activity";
break;
case 'mysql':
$sql = "show status where `variable_name` = 'Threads_connected'";
break;
default:
unset($sql);
if ($db_path != '' && $dbfilename != '') {
$tmp = shell_exec("lsof ".realpath($db_path).'/'.$dbfilename);
$tmp = explode("\n", $tmp);
$connections = sizeof($tmp) - 1;
}
}
if ($sql != '') {
$database = new database;
$connections = $database->select($sql, null, 'column');
unset($sql);
}
if ($connections != '') {
echo "<tr class='tr_link_void'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-database_connections']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$connections."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
//channel count
if ($fp) {
$tmp = event_socket_request($fp, 'api status');
$matches = Array();
preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches);
$channels = $matches[1] ? $matches[1] : 0;
$tr_link = "href='".PROJECT_PATH."/app/calls_active/calls_active.php'";
echo "<tr ".$tr_link.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'><a ".$tr_link.">".$text['label-channels']."</a></td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$channels."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
//registration count
if ($fp && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/registrations/")) {
$registration = new registrations;
$registrations = $registration->count();
$tr_link = "href='".PROJECT_PATH."/app/registrations/registrations.php'";
echo "<tr ".$tr_link.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'><a ".$tr_link.">".$text['label-registrations']."</a></td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'>".$registrations."</td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
echo "</table>\n";
echo "</div>";
$n++;
2021-11-10 02:42:14 +01:00
2021-11-10 07:16:50 +01:00
echo "<span class='hud_expander' onclick=\"$('#hud_system_status_details').slideToggle('fast');\"><span class='fas fa-ellipsis-h'></span></span>";
echo "</div>\n";
2021-11-10 06:38:15 +01:00
?>