From 7cb987434e2ebdf82eed8969a48c20aded0f7c33 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:24:29 +0800 Subject: [PATCH] feat(container): Align Container Memory Usage Display with Docker Stats (#7435) --- agent/app/service/container.go | 7 +- frontend/src/components/back-button/index.vue | 2 - frontend/src/components/group/index.vue | 137 ++++++++---------- 3 files changed, 69 insertions(+), 77 deletions(-) diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 88491c7d3..c48f885f0 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -1052,6 +1052,9 @@ func calculateCPUPercentUnix(stats *container.StatsResponse) float64 { func calculateMemPercentUnix(memStats container.MemoryStats) float64 { memPercent := 0.0 memUsage := float64(memStats.Usage) + if memStats.Stats["inactive_file"] > 0 { + memUsage = memUsage - float64(memStats.Stats["inactive_file"]) + } memLimit := float64(memStats.Limit) if memUsage > 0.0 && memLimit > 0.0 { memPercent = (memUsage / memLimit) * 100.0 @@ -1162,8 +1165,8 @@ func loadCpuAndMem(client *client.Client, containerItem string) dto.ContainerLis data.CPUPercent = calculateCPUPercentUnix(stats) data.PercpuUsage = len(stats.CPUStats.CPUUsage.PercpuUsage) - data.MemoryCache = stats.MemoryStats.Stats["cache"] - data.MemoryUsage = stats.MemoryStats.Usage + data.MemoryCache = stats.MemoryStats.Stats["inactive_file"] + data.MemoryUsage = stats.MemoryStats.Usage - data.MemoryCache data.MemoryLimit = stats.MemoryStats.Limit data.MemoryPercent = calculateMemPercentUnix(stats.MemoryStats) diff --git a/frontend/src/components/back-button/index.vue b/frontend/src/components/back-button/index.vue index 65dc1a583..53c09a888 100644 --- a/frontend/src/components/back-button/index.vue +++ b/frontend/src/components/back-button/index.vue @@ -1,8 +1,6 @@