forked from shirou/gopsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.go
50 lines (44 loc) · 1.2 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
package gopsutil
import (
"encoding/json"
"runtime"
)
type CPUTimesStat struct {
CPU string `json:"cpu"`
User float32 `json:"user"`
System float32 `json:"system"`
Idle float32 `json:"idle"`
Nice float32 `json:"nice"`
Iowait float32 `json:"iowait"`
Irq float32 `json:"irq"`
Softirq float32 `json:"softirq"`
Steal float32 `json:"steal"`
Guest float32 `json:"guest"`
GuestNice float32 `json:"guest_nice"`
Stolen float32 `json:"stolen"`
}
type CPUInfoStat struct {
CPU int32 `json:"cpu"`
VendorID string `json:"vendorId"`
Family string `json:"family"`
Model string `json:"model"`
Stepping int32 `json:"stepping"`
PhysicalID string `json:"physicalId"`
CoreID string `json:"coreId"`
Cores int32 `json:"cores"`
ModelName string `json:"modelName"`
Mhz float64 `json:"mhz"`
CacheSize int32 `json:"cacheSize"`
Flags []string `json:"flags"`
}
func CPUCounts(logical bool) (int, error) {
return runtime.NumCPU(), nil
}
func (c CPUTimesStat) String() string {
s, _ := json.Marshal(c)
return string(s)
}
func (c CPUInfoStat) String() string {
s, _ := json.Marshal(c)
return string(s)
}