From fc5c0176668402695c0d5c770c581e690c4263a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 30 Jun 2022 23:50:47 +0200 Subject: [PATCH] stats ice Candidates Count. --- internal/webrtc/manager.go | 8 ++++++++ internal/webrtc/metrics.go | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index 3d5c32c7..e95e13b8 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -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) + } + } } }() diff --git a/internal/webrtc/metrics.go b/internal/webrtc/metrics.go index 57e719e6..14daf21b 100644 --- a/internal/webrtc/metrics.go +++ b/internal/webrtc/metrics.go @@ -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)