From 11bc1c7fc273b2e215e8f65a27a433e53032c256 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Fri, 25 Apr 2025 06:23:26 -0700 Subject: [PATCH] fix: fixes total limit memory with multiple containers on the same host (#3842) --- .../LogViewer/MultiContainerStat.vue | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/assets/components/LogViewer/MultiContainerStat.vue b/assets/components/LogViewer/MultiContainerStat.vue index e32e9ef8..9017105e 100644 --- a/assets/components/LogViewer/MultiContainerStat.vue +++ b/assets/components/LogViewer/MultiContainerStat.vue @@ -55,15 +55,42 @@ watch( { immediate: true }, ); -const limits = computed(() => - containers.reduce( - (acc, c) => ({ - cpu: acc.cpu + (c.cpuLimit > 0 ? c.cpuLimit : hosts.value[c.host].nCPU), - memory: acc.memory + (c.memoryLimit > 0 ? c.memoryLimit : hosts.value[c.host].memTotal), - }), +const limits = computed(() => { + const hostLimits = new Map(); + + for (const container of containers) { + if (!hostLimits.has(container.host)) { + hostLimits.set(container.host, { + cpu: 0, + memory: 0, + }); + } + if (hostLimits.get(container.host)!.cpu < hosts.value[container.host].nCPU) { + if (container.cpuLimit == 0) { + hostLimits.get(container.host)!.cpu = hosts.value[container.host].nCPU; + } else { + hostLimits.get(container.host)!.cpu = hostLimits.get(container.host)!.cpu + container.cpuLimit; + } + } + if (hostLimits.get(container.host)!.memory < hosts.value[container.host].memTotal) { + if (container.memoryLimit == 0) { + hostLimits.get(container.host)!.memory = hosts.value[container.host].memTotal; + } else { + hostLimits.get(container.host)!.memory = hostLimits.get(container.host)!.memory + container.memoryLimit; + } + } + } + + return hostLimits.values().reduce( + (acc, { cpu, memory }) => { + return { + cpu: acc.cpu + cpu, + memory: acc.memory + memory, + }; + }, { cpu: 0, memory: 0 }, - ), -); + ); +}); useIntervalFn(() => { totalStat.value = containers.reduce(