From b9ef776bcf847ef5bb194ca17ce98c754055ccc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 12 Oct 2021 18:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=B4=9F?= =?UTF-8?q?=E8=BD=BD=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/cpu.go | 5 +++++ system/define.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/system/cpu.go b/system/cpu.go index 9801456..7c4e8e2 100644 --- a/system/cpu.go +++ b/system/cpu.go @@ -10,6 +10,8 @@ package system import ( "time" + "github.com/shirou/gopsutil/load" + "github.com/shirou/gopsutil/cpu" ) @@ -42,6 +44,8 @@ func GetCPUInfo() (*CPUDetail, error) { logicalCnt, _ := cpu.Counts(true) physicalCnt, _ := cpu.Counts(false) + avg, _ := load.Avg() + return &CPUDetail{ BaseInfo: baseInfo, Time: cpuTimeList, @@ -50,5 +54,6 @@ func GetCPUInfo() (*CPUDetail, error) { Logical: logicalCnt, Physical: physicalCnt, }, + Load: avg, }, nil } diff --git a/system/define.go b/system/define.go index aeb870f..0a773fc 100644 --- a/system/define.go +++ b/system/define.go @@ -7,7 +7,10 @@ // Date : 2021-10-12 5:48 下午 package system -import "github.com/shirou/gopsutil/cpu" +import ( + "github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/load" +) // CPUDetail CPU详情 // @@ -19,6 +22,7 @@ type CPUDetail struct { Time []cpu.TimesStat `json:"time"` // cpu时间 Percent []float64 `json:"percent"` // 使用率 CoreCntInfo CPUCoreCnt `json:"cnt_info"` // 核心数信息 + Load *load.AvgStat `json:"load"` // 负载信息 } // CPUCoreCnt cpu核数信息