Files
livekit/pkg/telemetry/prometheus/node_linux.go
Mathew Kamkar cac6d22a72 store cpu load in node stats (#524)
* store cpu load in node stats

* num cpus uint32

* cpu load selector test

* dep update
2022-03-16 14:51:22 -07:00

29 lines
533 B
Go

//go:build linux
// +build linux
package prometheus
import (
"github.com/mackerelio/go-osstat/cpu"
)
var lastCPUTotal, lastCPUIdle uint64
func getCPUStats() (cpuLoad float32, numCPUs uint32, err error) {
cpuInfo, err := cpu.Get()
if err != nil {
return
}
if lastCPUTotal > 0 && lastCPUTotal < cpuInfo.Total {
cpuLoad = 1 - float32(cpuInfo.Idle-lastCPUIdle)/float32(cpuInfo.Total-lastCPUTotal)
}
lastCPUTotal = cpuInfo.Total
lastCPUIdle = cpuInfo.Idle // + cpu.Iowait
numCPUs = uint32(cpuInfo.CPUCount)
return
}