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

pull/71/head
WAKAYAMA Shirou 10 years ago
parent bb04b692c3
commit 4696985e84

@ -14,7 +14,7 @@ import (
) )
type Win32_Processor struct { type Win32_Processor struct {
LoadPercentage uint16 LoadPercentage *uint16
Family uint16 Family uint16
Manufacturer string Manufacturer string
Name string Name string
@ -70,7 +70,6 @@ func CPUInfo() ([]CPUInfoStat, error) {
procID = *l.ProcessorId procID = *l.ProcessorId
} }
cpu := CPUInfoStat{ cpu := CPUInfoStat{
CPU: int32(i), CPU: int32(i),
Family: fmt.Sprintf("%d", l.Family), Family: fmt.Sprintf("%d", l.Family),
@ -97,7 +96,10 @@ func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
} }
for _, l := range dst { for _, l := range dst {
// use range but windows can only get one percent. // 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 return ret, nil
} }

Loading…
Cancel
Save