Consolidate getMemoryStats (#1122)
* Consolidate getMemoryStats * Avoid divide-by-0
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mackerelio/go-osstat/loadavg"
|
||||
"github.com/mackerelio/go-osstat/memory"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
@@ -84,6 +85,18 @@ func Init(nodeID string) {
|
||||
initRoomStats(nodeID)
|
||||
}
|
||||
|
||||
func getMemoryStats() (memoryLoad float32, err error) {
|
||||
memInfo, err := memory.Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if memInfo.Total != 0 {
|
||||
memoryLoad = float32(memInfo.Used) / float32(memInfo.Total)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats) (*livekit.NodeStats, bool, error) {
|
||||
loadAvg, err := loadavg.Get()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user