feat: Live-Metriken via WebSockets (Phase 3)

This commit is contained in:
Hitonabi
2026-06-20 23:30:58 +02:00
parent ee8ec10119
commit d0ed4e4c7e
3 changed files with 36 additions and 8 deletions
+20 -5
View File
@@ -72,9 +72,24 @@ async function pollJobs() {
catch { /* still */ }
}
async function pollSystem() {
try { applySystem(await api("/api/system/status")); }
catch { /* still */ }
function connectSystemStream() {
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const wsUrl = `${protocol}//${window.location.host}/api/system/stream`;
const ws = new WebSocket(wsUrl);
ws.onmessage = (e) => {
try {
const data = JSON.parse(e.data);
applySystem(data);
} catch (err) {}
};
ws.onclose = () => {
// Bei Verbindungsabbruch nach 3 Sekunden erneut versuchen
setTimeout(connectSystemStream, 3000);
};
ws.onerror = () => ws.close();
}
// ---- Boot ----
@@ -106,8 +121,8 @@ document.addEventListener("mc:refresh", pollStatus);
pollStatus();
pollJobs();
pollSystem();
connectSystemStream();
setInterval(tickClock, 1000);
setInterval(pollStatus, 3000);
setInterval(pollJobs, 1500);
setInterval(pollSystem, 2000);