本文整理匯總了Golang中github.com/elastic/gosigar.CpuList類的典型用法代碼示例。如果您正苦於以下問題:Golang CpuList類的具體用法?Golang CpuList怎麽用?Golang CpuList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CpuList類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetCpuTimesList
func GetCpuTimesList() ([]CpuTimes, error) {
cpuList := sigar.CpuList{}
err := cpuList.Get()
if err != nil {
return nil, err
}
cpuTimes := make([]CpuTimes, len(cpuList.List))
for i, cpu := range cpuList.List {
cpuTimes[i] = CpuTimes{
User: cpu.User,
Nice: cpu.Nice,
System: cpu.Sys,
Idle: cpu.Idle,
IOWait: cpu.Wait,
Irq: cpu.Irq,
SoftIrq: cpu.SoftIrq,
Steal: cpu.Stolen,
}
}
return cpuTimes, nil
}
示例2: GetCpuTimesList
func GetCpuTimesList() ([]CpuTimes, error) {
cpuList := sigar.CpuList{}
err := cpuList.Get()
if err != nil {
return nil, err
}
cpuTimes := make([]CpuTimes, len(cpuList.List))
for i, cpu := range cpuList.List {
cpuTimes[i] = CpuTimes{Cpu: cpu}
}
return cpuTimes, nil
}
示例3: GetSystemLoad
func GetSystemLoad() (*SystemLoad, error) {
concreteSigar := sigar.ConcreteSigar{}
avg, err := concreteSigar.GetLoadAverage()
if err != nil {
return nil, err
}
cpuList := sigar.CpuList{}
cpuList.Get()
numCore := len(cpuList.List)
return &SystemLoad{
Load1: avg.One,
Load5: avg.Five,
Load15: avg.Fifteen,
LoadNorm1: avg.One / float64(numCore),
LoadNorm5: avg.Five / float64(numCore),
LoadNorm15: avg.Fifteen / float64(numCore),
}, nil
}