-
Notifications
You must be signed in to change notification settings - Fork 90
/
cpu.go
56 lines (48 loc) · 1.37 KB
/
cpu.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//go:build windows
// +build windows
package windows
import (
"fmt"
"unsafe"
"github.com/mackerelio/mackerel-client-go"
"github.com/mackerelio/mackerel-agent/util/windows"
)
// CPUGenerator collects CPU specs
type CPUGenerator struct {
}
// Generate collects CPU specs.
func (g *CPUGenerator) Generate() (interface{}, error) {
var results mackerel.CPU
var systemInfo windows.SYSTEM_INFO
_, _, _ = windows.GetSystemInfo.Call(uintptr(unsafe.Pointer(&systemInfo)))
for i := uint32(0); i < systemInfo.NumberOfProcessors; i++ {
processorName, _, err := windows.RegGetString(
windows.HKEY_LOCAL_MACHINE,
fmt.Sprintf(`HARDWARE\DESCRIPTION\System\CentralProcessor\%d`, i),
`ProcessorNameString`)
if err != nil {
return nil, err
}
processorMHz, _, err := windows.RegGetInt(
windows.HKEY_LOCAL_MACHINE,
fmt.Sprintf(`HARDWARE\DESCRIPTION\System\CentralProcessor\%d`, i),
`~MHz`)
if err != nil {
return nil, err
}
vendorIdentifier, _, err := windows.RegGetString(
windows.HKEY_LOCAL_MACHINE,
fmt.Sprintf(`HARDWARE\DESCRIPTION\System\CentralProcessor\%d`, i),
`VendorIdentifier`)
if err != nil {
return nil, err
}
results = append(results, map[string]interface{}{
"model_name": processorName,
"mhz": processorMHz,
"model": systemInfo.ProcessorArchitecture,
"vendor_id": vendorIdentifier,
})
}
return results, nil
}