include packet and system info with node stats (#92)
* include packet and system info with node stats * add more packet and system stats * revert magefile, clean up system stats error handling * update procol version * dz review: error return
This commit is contained in:
@@ -2,9 +2,9 @@ package stats
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
linuxproc "github.com/c9s/goprocinfo/linux"
|
||||
livekit "github.com/livekit/livekit-server/proto"
|
||||
"github.com/pion/interceptor"
|
||||
"github.com/pion/rtcp"
|
||||
@@ -85,11 +85,33 @@ func (s *StatsInterceptor) BindLocalStream(_ *interceptor.StreamInfo, writer int
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateCurrentNodeStats(nodeStats *livekit.NodeStats) {
|
||||
nodeStats.NumClients = uint32(atomic.LoadInt32(&participantTotal))
|
||||
nodeStats.NumRooms = uint32(atomic.LoadInt32(&roomTotal))
|
||||
nodeStats.NumTracksIn = uint32(atomic.LoadInt32(&trackPublishedTotal))
|
||||
nodeStats.NumTracksOut = uint32(atomic.LoadInt32(&trackSubscribedTotal))
|
||||
|
||||
func UpdateCurrentNodeStats(nodeStats *livekit.NodeStats) error {
|
||||
updatedAtPrevious := nodeStats.UpdatedAt
|
||||
nodeStats.UpdatedAt = time.Now().Unix()
|
||||
secondsSinceLastUpdate := nodeStats.UpdatedAt - updatedAtPrevious
|
||||
|
||||
err := updateCurrentNodeSystemStats(nodeStats)
|
||||
updateCurrentNodeRoomStats(nodeStats)
|
||||
updateCurrentNodePacketStats(nodeStats, secondsSinceLastUpdate)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func updateCurrentNodeSystemStats(nodeStats *livekit.NodeStats) error {
|
||||
cpuInfo, err := linuxproc.ReadCPUInfo("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loadAvg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nodeStats.NumCpus = uint32(cpuInfo.NumCPU())
|
||||
nodeStats.LoadAvgLast1Min = float32(loadAvg.Last1Min)
|
||||
nodeStats.LoadAvgLast5Min = float32(loadAvg.Last5Min)
|
||||
nodeStats.LoadAvgLast15Min = float32(loadAvg.Last15Min)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user