From 7586bf875a22d17a6281f4a6c6822137bb31cd98 Mon Sep 17 00:00:00 2001 From: CoiaPrant <42506847+CoiaPrant@users.noreply.github.com> Date: Tue, 3 Aug 2021 22:01:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLXC=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E8=AF=BB=E5=8F=96=E5=86=85=E5=AD=98=E5=92=8CSwap?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/monitor/monitor.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/agent/monitor/monitor.go b/cmd/agent/monitor/monitor.go index 811753a..4b7786f 100644 --- a/cmd/agent/monitor/monitor.go +++ b/cmd/agent/monitor/monitor.go @@ -44,7 +44,6 @@ func GetHost() *model.Host { cpus = append(cpus, fmt.Sprintf("%s %d %s Core", model, count, cpuType)) } mv, _ := mem.VirtualMemory() - ms, _ := mem.SwapMemory() diskTotal, _ := getDiskTotalAndUsed() return &model.Host{ @@ -52,7 +51,7 @@ func GetHost() *model.Host { PlatformVersion: hi.PlatformVersion, CPU: cpus, MemTotal: mv.Total, - SwapTotal: ms.Total, + SwapTotal: mv.SwapTotal, DiskTotal: diskTotal, Arch: hi.KernelArch, Virtualization: hi.VirtualizationSystem, @@ -66,7 +65,6 @@ func GetHost() *model.Host { func GetState() *model.HostState { hi, _ := host.Info() mv, _ := mem.VirtualMemory() - ms, _ := mem.SwapMemory() var cpuPercent float64 cp, err := cpu.Percent(0, false) if err == nil { @@ -75,8 +73,8 @@ func GetState() *model.HostState { _, diskUsed := getDiskTotalAndUsed() return &model.HostState{ CPU: cpuPercent, - MemUsed: mv.Used, - SwapUsed: ms.Used, + MemUsed: mv.Total - mv.Available, + SwapUsed: mv.SwapTotal - mv.SwapFree, DiskUsed: diskUsed, NetInTransfer: atomic.LoadUint64(&netInTransfer), NetOutTransfer: atomic.LoadUint64(&netOutTransfer),