增加获取负载信息
This commit is contained in:
parent
dd6446c811
commit
b9ef776bcf
@ -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
|
||||
}
|
||||
|
@ -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核数信息
|
||||
|
Loading…
Reference in New Issue
Block a user