store cpu load in node stats (#524)
* store cpu load in node stats * num cpus uint32 * cpu load selector test * dep update
This commit is contained in:
@@ -4,23 +4,25 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
linuxproc "github.com/c9s/goprocinfo/linux"
|
||||
"github.com/mackerelio/go-osstat/cpu"
|
||||
)
|
||||
|
||||
func getSystemStats() (numCPUs uint32, avg1Min, avg5Min, avg15Min float32, err error) {
|
||||
cpuInfo, err := linuxproc.ReadCPUInfo("/proc/cpuinfo")
|
||||
var lastCPUTotal, lastCPUIdle uint64
|
||||
|
||||
func getCPUStats() (cpuLoad float32, numCPUs uint32, err error) {
|
||||
cpuInfo, err := cpu.Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
loadAvg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
|
||||
if err != nil {
|
||||
return
|
||||
if lastCPUTotal > 0 && lastCPUTotal < cpuInfo.Total {
|
||||
cpuLoad = 1 - float32(cpuInfo.Idle-lastCPUIdle)/float32(cpuInfo.Total-lastCPUTotal)
|
||||
}
|
||||
|
||||
numCPUs = uint32(cpuInfo.NumCPU())
|
||||
avg1Min = float32(loadAvg.Last1Min)
|
||||
avg5Min = float32(loadAvg.Last5Min)
|
||||
avg15Min = float32(loadAvg.Last15Min)
|
||||
lastCPUTotal = cpuInfo.Total
|
||||
lastCPUIdle = cpuInfo.Idle // + cpu.Iowait
|
||||
|
||||
numCPUs = uint32(cpuInfo.CPUCount)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user