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