forked from cloudradar-monitoring/cagent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpu_windows.go
35 lines (28 loc) · 1 KB
/
cpu_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// +build windows
package cagent
import (
"fmt"
"github.com/cloudradar-monitoring/cagent/pkg/winapi"
"github.com/shirou/gopsutil/cpu"
)
func systemProcessorPerformanceInfoToCPUTimesStat(core int, s *winapi.SystemProcessorPerformanceInformation) cpu.TimesStat {
return cpu.TimesStat{
CPU: fmt.Sprintf("cpu%d", core), // making consistent with other gopsutil/cpu implementations
Idle: float64(s.IdleTime) * winapi.HundredNSToTick,
System: float64(s.KernelTime-s.IdleTime) * winapi.HundredNSToTick,
User: float64(s.UserTime) * winapi.HundredNSToTick,
Irq: float64(s.InterruptTime) * winapi.HundredNSToTick,
}
}
func getCPUTimes() ([]cpu.TimesStat, error) {
var coreInfo []cpu.TimesStat
results, err := winapi.GetSystemProcessorPerformanceInformation()
if err != nil {
return coreInfo, err
}
coreInfo = make([]cpu.TimesStat, 0, len(results))
for core, info := range results {
coreInfo = append(coreInfo, systemProcessorPerformanceInfoToCPUTimesStat(core, &info))
}
return coreInfo, nil
}