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 }
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 }
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 }