mirror of
https://github.com/livekit/livekit.git
synced 2026-06-03 19:41:43 +00:00
add memory used and total to node stats (#1293)
* add memory used and total to node stats * raja review: consistency * update protocol
This commit is contained in:
@@ -85,18 +85,6 @@ func Init(nodeID string, nodeType livekit.NodeType) {
|
||||
initRoomStats(nodeID, nodeType)
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -108,9 +96,9 @@ func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
memoryLoad, _ := getMemoryStats()
|
||||
// On MacOS, get "\"vm_stat\": executable file not found in $PATH" although it is in /usr/bin
|
||||
// So, do not error out. Use the information if it is available.
|
||||
memInfo, _ := memory.Get()
|
||||
|
||||
sysPackets, sysDroppedPackets, err := getTCStats()
|
||||
if err != nil {
|
||||
@@ -166,12 +154,13 @@ func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats
|
||||
ParticipantJoinPerSec: prevAverage.ParticipantJoinPerSec,
|
||||
NumCpus: numCPUs,
|
||||
CpuLoad: cpuLoad,
|
||||
MemoryTotal: memInfo.Total,
|
||||
MemoryUsed: memInfo.Used,
|
||||
LoadAvgLast1Min: float32(loadAvg.Loadavg1),
|
||||
LoadAvgLast5Min: float32(loadAvg.Loadavg5),
|
||||
LoadAvgLast15Min: float32(loadAvg.Loadavg15),
|
||||
SysPacketsOut: sysPackets,
|
||||
SysPacketsDropped: sysDroppedPackets,
|
||||
MemoryLoad: memoryLoad,
|
||||
}
|
||||
|
||||
// update stats
|
||||
|
||||
Reference in New Issue
Block a user