mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 15:35:41 +00:00
31 lines
531 B
Go
31 lines
531 B
Go
//go:build !linux
|
|
// +build !linux
|
|
|
|
package prometheus
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"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
|
|
|
|
numCPUs = uint32(runtime.NumCPU())
|
|
|
|
return
|
|
}
|