mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
163060b3fa
* Update runc to 1.1.0 to get newer x/sys ...to fix building on Darwin with Go 1.18. This required some code changes as opencontainers unfortunately introduced breaking changes in a minor revision. However, those changes were to simpify the libcontainer factory initialization. * Switch CircleCI image to cimg/go, update remote Docker version to 20.10
47 lines
976 B
Go
47 lines
976 B
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package collector
|
|
|
|
import (
|
|
linuxproc "github.com/c9s/goprocinfo/linux"
|
|
)
|
|
|
|
var sysMemTotal = getSysMemTotal()
|
|
|
|
const (
|
|
clockTicksPerSecond uint64 = 100
|
|
nanoSecondsPerSecond = 1e9
|
|
)
|
|
|
|
func getSysMemTotal() int64 {
|
|
stat, err := linuxproc.ReadMemInfo("/proc/meminfo")
|
|
if err != nil {
|
|
log.Errorf("error reading system stats: %s", err)
|
|
return 0
|
|
}
|
|
return int64(stat.MemTotal * 1024)
|
|
}
|
|
|
|
// return cumulative system cpu usage in nanoseconds
|
|
func getSysCPUUsage() uint64 {
|
|
stat, err := linuxproc.ReadStat("/proc/stat")
|
|
if err != nil {
|
|
log.Errorf("error reading system stats: %s", err)
|
|
return 0
|
|
}
|
|
|
|
sum := stat.CPUStatAll.User +
|
|
stat.CPUStatAll.Nice +
|
|
stat.CPUStatAll.System +
|
|
stat.CPUStatAll.Idle +
|
|
stat.CPUStatAll.IOWait +
|
|
stat.CPUStatAll.IRQ +
|
|
stat.CPUStatAll.SoftIRQ +
|
|
stat.CPUStatAll.Steal +
|
|
stat.CPUStatAll.Guest +
|
|
stat.CPUStatAll.GuestNice
|
|
|
|
return (sum * nanoSecondsPerSecond) / clockTicksPerSecond
|
|
}
|