stats ice Candidates Count.

This commit is contained in:
Miroslav Šedivý 2022-06-30 23:50:47 +02:00
parent 8e80ef2c69
commit fc5c017666
2 changed files with 34 additions and 0 deletions

View File

@ -411,6 +411,14 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
if ok {
manager.metrics.SetTransportStats(session, data)
}
for _, entry := range stats {
// only remote ice candidate stats
candidate, ok := entry.(webrtc.ICECandidateStats)
if ok && candidate.Type == webrtc.StatsTypeRemoteCandidate {
manager.metrics.NewICECandidate(session, candidate.ID)
}
}
}
}()

View File

@ -13,6 +13,9 @@ type metrics struct {
connectionState prometheus.Gauge
connectionCount prometheus.Counter
iceCandidates map[string]struct{}
iceCandidatesCount prometheus.Counter
bytesSent prometheus.Gauge
bytesReceived prometheus.Gauge
}
@ -57,6 +60,18 @@ func (m *metricsCtx) getBySession(session types.Session) metrics {
"session_id": session.ID(),
},
}),
iceCandidates: map[string]struct{}{},
iceCandidatesCount: promauto.NewCounter(prometheus.CounterOpts{
Name: "ice_candidates_count",
Namespace: "neko",
Subsystem: "webrtc",
Help: "Count of ICE candidates sent by a remote client.",
ConstLabels: map[string]string{
"session_id": session.ID(),
},
}),
bytesSent: promauto.NewGauge(prometheus.GaugeOpts{
Name: "bytes_sent",
Namespace: "neko",
@ -86,6 +101,17 @@ func (m *metricsCtx) NewConnection(session types.Session) {
met.connectionCount.Add(1)
}
func (m *metricsCtx) NewICECandidate(session types.Session, id string) {
met := m.getBySession(session)
if _, found := met.iceCandidates[id]; found {
return
}
met.iceCandidates[id] = struct{}{}
met.iceCandidatesCount.Add(1)
}
func (m *metricsCtx) SetState(session types.Session, state webrtc.PeerConnectionState) {
met := m.getBySession(session)