2014-04-22 08:44:22 +08:00
|
|
|
package gopsutil
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import (
|
2014-05-01 17:43:11 +08:00
|
|
|
"encoding/json"
|
2014-04-18 15:34:47 +08:00
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
2014-04-30 14:32:05 +08:00
|
|
|
type CPUTimesStat struct {
|
2014-04-30 15:16:07 +08:00
|
|
|
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"`
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
2014-05-16 17:12:18 +08:00
|
|
|
type CPUInfoStat struct {
|
2014-05-16 17:39:17 +08:00
|
|
|
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"`
|
2014-05-16 17:12:18 +08:00
|
|
|
Flags []string `json:"flags"`
|
|
|
|
}
|
|
|
|
|
2014-04-30 15:16:07 +08:00
|
|
|
func CPUCounts(logical bool) (int, error) {
|
2014-04-18 15:34:47 +08:00
|
|
|
return runtime.NumCPU(), nil
|
|
|
|
}
|
2014-05-01 17:43:11 +08:00
|
|
|
|
|
|
|
func (c CPUTimesStat) String() string {
|
|
|
|
s, _ := json.Marshal(c)
|
|
|
|
return string(s)
|
|
|
|
}
|
2014-05-16 17:12:18 +08:00
|
|
|
|
|
|
|
func (c CPUInfoStat) String() string {
|
|
|
|
s, _ := json.Marshal(c)
|
|
|
|
return string(s)
|
|
|
|
}
|