|
|
|
@ -14,6 +14,8 @@ import (
|
|
|
|
|
const (
|
|
|
|
|
cpuTicks = 100
|
|
|
|
|
cpuFields = 8
|
|
|
|
|
cpuMax = 1000
|
|
|
|
|
statDir = "/proc/stat"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
@ -81,7 +83,10 @@ func RefreshCpu() uint64 {
|
|
|
|
|
cpuDelta := total - preTotal
|
|
|
|
|
systemDelta := system - preSystem
|
|
|
|
|
if cpuDelta > 0 && systemDelta > 0 {
|
|
|
|
|
usage = uint64(float64(cpuDelta*cores*1e3) / (float64(systemDelta) * quota))
|
|
|
|
|
usage = uint64(float64(cpuDelta*cores*cpuMax) / (float64(systemDelta) * quota))
|
|
|
|
|
if usage > cpuMax {
|
|
|
|
|
usage = cpuMax
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
preSystem = system
|
|
|
|
|
preTotal = total
|
|
|
|
@ -117,7 +122,7 @@ func cpuSets() ([]uint64, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func systemCpuUsage() (uint64, error) {
|
|
|
|
|
lines, err := iox.ReadTextLines("/proc/stat", iox.WithoutBlank())
|
|
|
|
|
lines, err := iox.ReadTextLines(statDir, iox.WithoutBlank())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|