mirror of
https://github.com/livekit/livekit.git
synced 2026-09-01 20:09:08 +00:00
Fix node stats updates on Windows (#1748)
Because we aren't able to get CPU count/load info on Windows, they are stubbed out to return placeholders. This restores compatibility to run on Windows.
This commit is contained in:
@@ -5,37 +5,10 @@ package prometheus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/florianl/go-tc"
|
||||
"github.com/mackerelio/go-osstat/cpu"
|
||||
)
|
||||
|
||||
var (
|
||||
cpuStatsLock sync.RWMutex
|
||||
lastCPUTotal, lastCPUIdle uint64
|
||||
)
|
||||
|
||||
func getCPUStats() (cpuLoad float32, numCPUs uint32, err error) {
|
||||
cpuInfo, err := cpu.Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cpuStatsLock.Lock()
|
||||
if lastCPUTotal > 0 && lastCPUTotal < cpuInfo.Total {
|
||||
cpuLoad = 1 - float32(cpuInfo.Idle-lastCPUIdle)/float32(cpuInfo.Total-lastCPUTotal)
|
||||
}
|
||||
|
||||
lastCPUTotal = cpuInfo.Total
|
||||
lastCPUIdle = cpuInfo.Idle // + cpu.Iowait
|
||||
cpuStatsLock.Unlock()
|
||||
|
||||
numCPUs = uint32(cpuInfo.CPUCount)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getTCStats() (packets, drops uint32, err error) {
|
||||
rtnl, err := tc.Open(&tc.Config{})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user