增加获取负载信息
This commit is contained in:
parent
dd6446c811
commit
b9ef776bcf
@ -10,6 +10,8 @@ package system
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/load"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,6 +44,8 @@ func GetCPUInfo() (*CPUDetail, error) {
|
|||||||
logicalCnt, _ := cpu.Counts(true)
|
logicalCnt, _ := cpu.Counts(true)
|
||||||
physicalCnt, _ := cpu.Counts(false)
|
physicalCnt, _ := cpu.Counts(false)
|
||||||
|
|
||||||
|
avg, _ := load.Avg()
|
||||||
|
|
||||||
return &CPUDetail{
|
return &CPUDetail{
|
||||||
BaseInfo: baseInfo,
|
BaseInfo: baseInfo,
|
||||||
Time: cpuTimeList,
|
Time: cpuTimeList,
|
||||||
@ -50,5 +54,6 @@ func GetCPUInfo() (*CPUDetail, error) {
|
|||||||
Logical: logicalCnt,
|
Logical: logicalCnt,
|
||||||
Physical: physicalCnt,
|
Physical: physicalCnt,
|
||||||
},
|
},
|
||||||
|
Load: avg,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@
|
|||||||
// Date : 2021-10-12 5:48 下午
|
// Date : 2021-10-12 5:48 下午
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import "github.com/shirou/gopsutil/cpu"
|
import (
|
||||||
|
"github.com/shirou/gopsutil/cpu"
|
||||||
|
"github.com/shirou/gopsutil/load"
|
||||||
|
)
|
||||||
|
|
||||||
// CPUDetail CPU详情
|
// CPUDetail CPU详情
|
||||||
//
|
//
|
||||||
@ -19,6 +22,7 @@ type CPUDetail struct {
|
|||||||
Time []cpu.TimesStat `json:"time"` // cpu时间
|
Time []cpu.TimesStat `json:"time"` // cpu时间
|
||||||
Percent []float64 `json:"percent"` // 使用率
|
Percent []float64 `json:"percent"` // 使用率
|
||||||
CoreCntInfo CPUCoreCnt `json:"cnt_info"` // 核心数信息
|
CoreCntInfo CPUCoreCnt `json:"cnt_info"` // 核心数信息
|
||||||
|
Load *load.AvgStat `json:"load"` // 负载信息
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPUCoreCnt cpu核数信息
|
// CPUCoreCnt cpu核数信息
|
||||||
|
Loading…
Reference in New Issue
Block a user