package stats import ( "time" "linkfog.com/public/lib/cgroup" "linkfog.com/public/lib/cgroup/fs" "linkfog.com/public/lib/cgroup/fs2" "linkfog.com/public/lib/cgroup/types" ) func GetCPUTotalUsage(cgroupDir string) (usage float64, err error) { var cpuStats types.CPUStats cpuStats, err = GetCPUStats(cgroupDir) if err != nil { return } usage = float64(cpuStats.TotalUsage) return } func GetCPUStats(cgroupDir string) (stats types.CPUStats, err error) { var totalUsage uint64 var perCPUUsage []uint64 if cgroup.IsCgroup2() { totalUsage, err = fs2.GetCPUUsage(cgroupDir) } else { totalUsage, perCPUUsage, err = fs.GetCPUUsage(cgroupDir) } if err != nil { return } stats.TotalUsage = totalUsage stats.PerCPUUsage = perCPUUsage stats.Timestamp = time.Now() return }