func Init() error { var err error onceLer.Do(func() { if cpuNumCores, err = cpu.Counts(true); err != nil { err = fmt.Errorf("Unable to determine the number of CPU cores available: %v", err) return } var cpuInfo []cpu.InfoStat if cpuInfo, err = cpu.Info(); err != nil { err = fmt.Errorf("Unable to obtain CPU information: %v", err) return } for _, cpu := range cpuInfo { cpuModelName = cpu.ModelName cpuMhzPerCore = cpu.Mhz break } // Floor all of the values such that small difference don't cause the // node to fall into a unique computed node class cpuMhzPerCore = math.Floor(cpuMhzPerCore) cpuTotalTicks = math.Floor(float64(cpuNumCores) * cpuMhzPerCore) }) return err }
// LoadAverage - returns load avg func LoadAverage() LoadStruct { cores, _ := cpu.Counts(true) load, _ := load.Avg() l := LoadStruct{ Minute: load.Load1, FiveMinutes: load.Load5, FifteenMinutes: load.Load15, Cores: cores, } return l }