MCPcopy
hub / github.com/livekit/livekit / GetNodeStats

Function GetNodeStats

pkg/telemetry/prometheus/node.go:137–206  ·  view source on GitHub ↗
(nodeStartedAt int64, prevStats []*livekit.NodeStats, rateIntervals []time.Duration)

Source from the content-addressed store, hash-verified

135}
136
137func GetNodeStats(nodeStartedAt int64, prevStats []*livekit.NodeStats, rateIntervals []time.Duration) (*livekit.NodeStats, error) {
138 loadAvg, err := getLoadAvg()
139 if err != nil {
140 return nil, err
141 }
142
143 // On MacOS, get "\"vm_stat\": executable file not found in $PATH" although it is in /usr/bin
144 // So, do not error out. Use the information if it is available.
145 memUsed, memTotal, _ := memoryStats.GetMemory()
146
147 sysPackets, sysDroppedPackets, _ := getTCStats()
148 promSysPacketGauge.WithLabelValues("out").Set(float64(sysPackets - sysPacketsStart))
149 promSysPacketGauge.WithLabelValues("dropped").Set(float64(sysDroppedPackets - sysDroppedPacketsStart))
150
151 stats := &livekit.NodeStats{
152 StartedAt: nodeStartedAt,
153 UpdatedAt: time.Now().Unix(),
154 NumRooms: roomCurrent.Load(),
155 NumClients: participantCurrent.Load(),
156 NumTracksIn: trackPublishedCurrent.Load(),
157 NumTracksOut: trackSubscribedCurrent.Load(),
158 NumTrackPublishAttempts: trackPublishAttempts.Load(),
159 NumTrackPublishSuccess: trackPublishSuccess.Load(),
160 NumTrackPublishCancels: trackPublishCancels.Load(),
161 NumTrackSubscribeAttempts: trackSubscribeAttempts.Load(),
162 NumTrackSubscribeSuccess: trackSubscribeSuccess.Load(),
163 NumTrackSubscribeCancels: trackSubscribeCancels.Load(),
164 BytesIn: bytesIn.Load(),
165 BytesOut: bytesOut.Load(),
166 PacketsIn: packetsIn.Load(),
167 PacketsOut: packetsOut.Load(),
168 RetransmitBytesOut: retransmitBytes.Load(),
169 RetransmitPacketsOut: retransmitPackets.Load(),
170 NackTotal: nackTotal.Load(),
171 ParticipantSignalConnected: participantSignalConnected.Load(),
172 ParticipantRtcInit: participantRTCInit.Load(),
173 ParticipantRtcConnected: participantRTCConnected.Load(),
174 ParticipantRtcCanceled: participantRTCCanceled.Load(),
175 ParticipantRtcActive: participantRTCActive.Load(),
176 ForwardLatency: forwardLatency.Load(),
177 ForwardJitter: forwardJitter.Load(),
178 NumCpus: uint32(cpuStats.NumCPU()), // this will round down to the nearest integer
179 CpuLoad: float32(cpuStats.GetCPULoad()),
180 MemoryTotal: memTotal,
181 MemoryUsed: memUsed,
182 LoadAvgLast1Min: float32(loadAvg.Loadavg1),
183 LoadAvgLast5Min: float32(loadAvg.Loadavg5),
184 LoadAvgLast15Min: float32(loadAvg.Loadavg15),
185 SysPacketsOut: sysPackets,
186 SysPacketsDropped: sysDroppedPackets,
187 }
188
189 for _, rateInterval := range rateIntervals {
190 for idx := len(prevStats) - 1; idx >= 0; idx-- {
191 prev := prevStats[idx]
192 if prev == nil {
193 continue
194 }

Callers 1

UpdateAndGetNodeStatsMethod · 0.92

Calls 4

getNodeStatsRateFunction · 0.85
getLoadAvgFunction · 0.70
getTCStatsFunction · 0.70
LoadMethod · 0.65

Tested by

no test coverage detected