From 13aa1b9424117b667d30731f5d1402dfdde8cd6a Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Fri, 30 Aug 2024 19:22:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96CPU=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=94=B9=E6=88=901=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/resource.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/resource.go b/system/resource.go index 6b80018..32ef3c6 100644 --- a/system/resource.go +++ b/system/resource.go @@ -7,6 +7,7 @@ import ( "github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/mem" + "time" ) type resource struct { @@ -33,13 +34,13 @@ func (receiver *resource) ToString() string { // GetResource 获取当前环境信息 func GetResource() *resource { - info, _ := cpu.Percent(0, false) + info, _ := cpu.Percent(time.Second, false) infoStats, _ := cpu.Info() memory, _ := mem.VirtualMemory() hostInfo, _ := host.Info() diskUsage, _ := disk.Usage("/") if len(infoStats) == 0 { - infoStats = []cpu.InfoStat{cpu.InfoStat{}} + infoStats = []cpu.InfoStat{{}} } if len(info) == 0 { info = []float64{float64(0)}