changed server load stats

This commit is contained in:
Janis Steiner
2024-10-14 13:12:21 +01:00
parent c7a644a8e4
commit 017c34e2d5
3 changed files with 119 additions and 39 deletions

View File

@@ -75,6 +75,9 @@ async function delete_input(input,action,id,row){
<a class="nav-link" href="debug.php?show=filament_settings" id="filament_settings_tab">Filamenteinstellungen</a>
</li>
<li class="nav-item">
<a class="nav-link" href="debug.php?show=srv_stats" id="srv_stats_tab">Serverstatistiken</a>
</li>
</ul>
<div id="printer_settings" style="display:none">
<h1>Druckerfreigabe erzwingen (falls beim freigeben Fehlermeldungen angezeigt werden)</h1>
@@ -295,9 +298,32 @@ async function delete_input(input,action,id,row){
}
echo("</tbody></table></div></div></div>");
echo("</div>");
?>
</div>
<div id="srv_stats" style="display:none">
<div class="container my-5">
<h1 class="text-center mb-4">Server Stats</h1>
<div id="stats" class="row text-center">
<!-- Stats will be dynamically loaded here via AJAX -->
</div>
</div>
<script>
function refreshStats() {
$.ajax({
url: "/api/server_stats.php", // Load from server_stats.php, which includes auth and stats
method: "GET",
success: function (data) {
$("#stats").html(data);
}
});
}
refreshStats();
setInterval(refreshStats, 1000);
</script>
</div>
<?php
test_queue($link);
?>

View File

@@ -1,38 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server Stats</title>
</head>
<body>
<div id="stats"></div>
<script>
function refreshStats() {
location.reload();
}
// Refresh stats every 1 second
setInterval(refreshStats, 1000);
</script>
<?php
// Get server load
$load = sys_getloadavg();
// Get CPU usage
$cpu_usage = shell_exec("top -bn1 | grep 'Cpu(s)' | sed 's/.*, *\\([0-9.]*\\)%* id.*/\\1/' | awk '{print 100 - $1\"%\"}'");
// Get RAM usage
$ram_usage = shell_exec("free | grep Mem | awk '{print $3/$2 * 100.0\"%\"}'");
// Display results
echo "Server Load: " . implode(", ", $load) . "<br>";
echo "CPU Usage: " . $cpu_usage . "<br>";
echo "RAM Usage: " . $ram_usage . "<br>";
?>
</body>
</html>