Compare commits

..

2 Commits

Author SHA1 Message Date
bf0bf6b185 Changes made to glances 2026-02-12 22:52:09 +01:00
fb88376155 Changes made to glances 2026-02-12 22:51:57 +01:00

View File

@@ -120,12 +120,19 @@
// Rich monitor parsers // Rich monitor parsers
this.parsers = { this.parsers = {
glances: (data) => `CPU ${Math.round(data.cpu_percent)}% | RAM ${Math.round(data.mem_percent)}%`, glances: (data) => {
// Glances v4 uses 'cpu'/'mem', v3 uses 'cpu_percent'/'mem_percent'
const cpu = data.cpu ?? data.cpu_percent;
const mem = data.mem ?? data.mem_percent;
if (cpu == null || mem == null) return 'No data';
return `CPU ${Math.round(cpu)}% | RAM ${Math.round(mem)}%`;
},
uptime: (data) => { uptime: (data) => {
const groups = data.heartbeatList || {}; const groups = data.heartbeatList || {};
const monitors = Object.values(groups); const monitors = Object.values(groups);
const total = monitors.length; const total = monitors.length;
const up = monitors.filter(beats => beats.length > 0 && beats[beats.length - 1].status === 1).length; if (total === 0) return 'No monitors';
const up = monitors.filter(beats => Array.isArray(beats) && beats.length > 0 && beats[beats.length - 1].status === 1).length;
return `${up}/${total} services up`; return `${up}/${total} services up`;
}, },
cadvisor: (data) => { cadvisor: (data) => {
@@ -162,9 +169,12 @@
if (!res.ok) throw new Error(`HTTP ${res.status}`); if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json(); const data = await res.json();
console.log(`[StatusMonitor] ${mon.label} raw:`, JSON.stringify(data).slice(0, 500));
const result = this.parsers[mon.parseType](data);
dot.className = 'status-dot ok'; dot.className = 'status-dot ok';
value.textContent = this.parsers[mon.parseType](data); value.textContent = result;
} catch { } catch (err) {
console.warn(`[StatusMonitor] ${mon.label} failed:`, err);
dot.className = 'status-dot error'; dot.className = 'status-dot error';
value.textContent = 'Unreachable'; value.textContent = 'Unreachable';
} }