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核数信息