feat(containers-dashboard): podheader uitgebreid met cpu en mem totalen
This commit is contained in:
+35
-2
@@ -707,6 +707,7 @@
|
|||||||
|
|
||||||
const table = tbody.closest('table');
|
const table = tbody.closest('table');
|
||||||
const colCount = table ? table.querySelectorAll('thead th').length : 9;
|
const colCount = table ? table.querySelectorAll('thead th').length : 9;
|
||||||
|
containersC2P = new Map();
|
||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
|
|
||||||
@@ -768,8 +769,9 @@
|
|||||||
<td class="muted">-</td>
|
<td class="muted">-</td>
|
||||||
<td class="muted">-</td>
|
<td class="muted">-</td>
|
||||||
<td>${isRealPod ? '<span class="btn small muted">pod</span>' : '<span class="muted">-</span>'}</td>
|
<td>${isRealPod ? '<span class="btn small muted">pod</span>' : '<span class="muted">-</span>'}</td>
|
||||||
<td class="muted num">-</td>
|
|
||||||
<td class="muted num">-</td>
|
<td class="muted num" id="podcpu-${cssSafeId(pod)}">-</td>
|
||||||
|
<td class="muted num" id="podmem-${cssSafeId(pod)}">-</td>
|
||||||
<td class="mono">${esc(podPortsText)}</td>
|
<td class="mono">${esc(podPortsText)}</td>
|
||||||
<td>
|
<td>
|
||||||
${isRealPod ? `
|
${isRealPod ? `
|
||||||
@@ -787,6 +789,8 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
for (const c of items) {
|
for (const c of items) {
|
||||||
|
const cname = normalizeContainerName((c.Names && c.Names[0]) ? c.Names[0] : (c.Names || c.Name || c.name || ''));
|
||||||
|
if (cname) containersC2P.set(cname, pod);
|
||||||
const row = renderContainerRow(c).replace(
|
const row = renderContainerRow(c).replace(
|
||||||
'<tr',
|
'<tr',
|
||||||
`<tr class="pod-item-row" data-pod="${pod}"${collapsed ? ' style="display:none;"' : ''}`
|
`<tr class="pod-item-row" data-pod="${pod}"${collapsed ? ' style="display:none;"' : ''}`
|
||||||
@@ -838,6 +842,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let containersStatsES = null;
|
let containersStatsES = null;
|
||||||
|
let containersC2P = new Map();
|
||||||
|
|
||||||
function startContainersStatsStream() {
|
function startContainersStatsStream() {
|
||||||
if (containersStatsES) return;
|
if (containersStatsES) return;
|
||||||
@@ -847,6 +852,10 @@
|
|||||||
containersStatsES.addEventListener("stats", (ev) => {
|
containersStatsES.addEventListener("stats", (ev) => {
|
||||||
const payload = JSON.parse(ev.data);
|
const payload = JSON.parse(ev.data);
|
||||||
const statsList = payload?.data?.Stats || [];
|
const statsList = payload?.data?.Stats || [];
|
||||||
|
// totals per pod voor deze SSE tick
|
||||||
|
const podCpu = new Map(); // podName -> cpuPct sum
|
||||||
|
const podMem = new Map(); // podName -> memBytes sum
|
||||||
|
const podMemPct = new Map(); // podName -> memPct sum
|
||||||
|
|
||||||
for (const st of statsList) {
|
for (const st of statsList) {
|
||||||
const cname = normalizeContainerName(st?.Name);
|
const cname = normalizeContainerName(st?.Name);
|
||||||
@@ -854,6 +863,30 @@
|
|||||||
|
|
||||||
const key = cssSafeId(cname);
|
const key = cssSafeId(cname);
|
||||||
|
|
||||||
|
const pod = containersC2P.get(cname);
|
||||||
|
if (pod) {
|
||||||
|
const cpuPct = Number(st?.CPUPerc ?? st?.CPU ?? st?.AvgCPU ?? 0);
|
||||||
|
const memBytes = Number(st?.MemUsage ?? 0);
|
||||||
|
const memPct = Number(st?.MemPerc ?? 0);
|
||||||
|
|
||||||
|
podCpu.set(pod, (podCpu.get(pod) || 0) + cpuPct);
|
||||||
|
podMem.set(pod, (podMem.get(pod) || 0) + memBytes);
|
||||||
|
podMemPct.set(pod, (podMemPct.get(pod) || 0) + memPct);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [pod, cpuSum] of podCpu.entries()) {
|
||||||
|
const el = document.getElementById(`podcpu-${cssSafeId(pod)}`);
|
||||||
|
if (el) el.textContent = cpuSum.toFixed(2) + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [pod, memSum] of podMem.entries()) {
|
||||||
|
const el = document.getElementById(`podmem-${cssSafeId(pod)}`);
|
||||||
|
if (el) {
|
||||||
|
const memPct = podMemPct.get(pod) || 0;
|
||||||
|
el.textContent = `${formatBytes(memSum)} (${memPct.toFixed(1)}%)`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CPU: jouw API geeft CPU als fractie (0.00384 -> 0.384%)
|
// CPU: jouw API geeft CPU als fractie (0.00384 -> 0.384%)
|
||||||
const cpuPct = Number(st?.CPUPerc ?? st?.CPU ?? st?.AvgCPU ?? 0);
|
const cpuPct = Number(st?.CPUPerc ?? st?.CPU ?? st?.AvgCPU ?? 0);
|
||||||
const cpuEl = document.getElementById(`cpu-${key}`);
|
const cpuEl = document.getElementById(`cpu-${key}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user