MCPcopy
hub / github.com/livekit/livekit / TrackStats

Method TrackStats

pkg/telemetry/stats.go:65–114  ·  view source on GitHub ↗
(roomID livekit.RoomID, _roomName livekit.RoomName, key StatsKey, stat *livekit.AnalyticsStat)

Source from the content-addressed store, hash-verified

63}
64
65func (t *telemetryService) TrackStats(roomID livekit.RoomID, _roomName livekit.RoomName, key StatsKey, stat *livekit.AnalyticsStat) {
66 t.enqueue(func() {
67 direction := prometheus.Incoming
68 if key.streamType == livekit.StreamType_DOWNSTREAM {
69 direction = prometheus.Outgoing
70 }
71
72 nacks := uint32(0)
73 plis := uint32(0)
74 firs := uint32(0)
75 packets := uint32(0)
76 bytes := uint64(0)
77 retransmitBytes := uint64(0)
78 retransmitPackets := uint32(0)
79 for _, stream := range stat.Streams {
80 nacks += stream.Nacks
81 plis += stream.Plis
82 firs += stream.Firs
83 packets += stream.PrimaryPackets + stream.PaddingPackets
84 bytes += stream.PrimaryBytes + stream.PaddingBytes
85 if key.streamType == livekit.StreamType_DOWNSTREAM {
86 retransmitPackets += stream.RetransmitPackets
87 retransmitBytes += stream.RetransmitBytes
88 } else {
89 // for upstream, we don't account for these separately for now
90 packets += stream.RetransmitPackets
91 bytes += stream.RetransmitBytes
92 }
93 if key.track {
94 prometheus.RecordPacketLoss(key.country, direction, key.trackSource, key.trackType, stream.PacketsLost, stream.PrimaryPackets+stream.PaddingPackets)
95 prometheus.RecordPacketOutOfOrder(key.country, direction, key.trackSource, key.trackType, stream.PacketsOutOfOrder, stream.PrimaryPackets+stream.PaddingPackets)
96 prometheus.RecordRTT(key.country, direction, key.trackSource, key.trackType, stream.Rtt)
97 prometheus.RecordJitter(key.country, direction, key.trackSource, key.trackType, stream.Jitter)
98 }
99 }
100 prometheus.IncrementRTCP(key.country, direction, nacks, plis, firs)
101 prometheus.IncrementPackets(key.country, direction, uint64(packets), false)
102 prometheus.IncrementBytes(key.country, direction, bytes, false)
103 if retransmitPackets != 0 {
104 prometheus.IncrementPackets(key.country, direction, uint64(retransmitPackets), true)
105 }
106 if retransmitBytes != 0 {
107 prometheus.IncrementBytes(key.country, direction, retransmitBytes, true)
108 }
109
110 if worker, ok := t.getWorker(roomID, key.participantID); ok {
111 worker.OnTrackStat(key.trackID, key.streamType, stat)
112 }
113 })
114}

Callers

nothing calls this directly

Calls 10

enqueueMethod · 0.95
getWorkerMethod · 0.95
RecordPacketLossFunction · 0.92
RecordPacketOutOfOrderFunction · 0.92
RecordRTTFunction · 0.92
RecordJitterFunction · 0.92
IncrementRTCPFunction · 0.92
IncrementPacketsFunction · 0.92
IncrementBytesFunction · 0.92
OnTrackStatMethod · 0.80

Tested by

no test coverage detected