提交 4696985e 编写于 作者: W WAKAYAMA Shirou

cpu[windows]: skip if could not get cpu.LoadPercentage.

上级 bb04b692
......@@ -14,7 +14,7 @@ import (
)
type Win32_Processor struct {
LoadPercentage uint16
LoadPercentage *uint16
Family uint16
Manufacturer string
Name string
......@@ -62,15 +62,14 @@ func CPUInfo() ([]CPUInfoStat, error) {
if err != nil {
return ret, err
}
var procID string
for i, l := range dst {
for i, l := range dst {
procID = ""
if l.ProcessorId != nil {
procID = *l.ProcessorId
}
cpu := CPUInfoStat{
CPU: int32(i),
Family: fmt.Sprintf("%d", l.Family),
......@@ -97,7 +96,10 @@ func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
}
for _, l := range dst {
// use range but windows can only get one percent.
ret = append(ret, float64(l.LoadPercentage)/100.0)
if l.LoadPercentage == nil {
continue
}
ret = append(ret, float64(*l.LoadPercentage)/100.0)
}
return ret, nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册