replace entire nodeStats object (#393)

This commit is contained in:
David Colburn
2022-01-31 17:09:36 -07:00
committed by GitHub
parent 745939ec24
commit 3d132730f9
6 changed files with 66 additions and 67 deletions
+8 -10
View File
@@ -5,24 +5,22 @@ package prometheus
import (
linuxproc "github.com/c9s/goprocinfo/linux"
"github.com/livekit/protocol/livekit"
)
func updateCurrentNodeSystemStats(nodeStats *livekit.NodeStats) error {
func getSystemStats() (numCPUs uint32, avg1Min, avg5Min, avg15Min float32, err error) {
cpuInfo, err := linuxproc.ReadCPUInfo("/proc/cpuinfo")
if err != nil {
return err
return
}
loadAvg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
if err != nil {
return err
return
}
nodeStats.NumCpus = uint32(cpuInfo.NumCPU())
nodeStats.LoadAvgLast1Min = float32(loadAvg.Last1Min)
nodeStats.LoadAvgLast5Min = float32(loadAvg.Last5Min)
nodeStats.LoadAvgLast15Min = float32(loadAvg.Last15Min)
return nil
numCPUs = uint32(cpuInfo.NumCPU())
avg1Min = float32(loadAvg.Last1Min)
avg5Min = float32(loadAvg.Last5Min)
avg15Min = float32(loadAvg.Last15Min)
return
}