From bb3569525551ffa8053e64e0964a2179890b967d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 1 Jul 2022 00:16:39 +0200 Subject: [PATCH] split sctp and ice bytes. --- internal/webrtc/manager.go | 7 +++++- internal/webrtc/metrics.go | 50 +++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index e95e13b8..c6dec0c0 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -409,7 +409,12 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin stats := connection.GetStats() data, ok := stats["iceTransport"].(webrtc.TransportStats) if ok { - manager.metrics.SetTransportStats(session, data) + manager.metrics.SetIceTransportStats(session, data) + } + + data, ok = stats["sctpTransport"].(webrtc.TransportStats) + if ok { + manager.metrics.SetSctpTransportStats(session, data) } for _, entry := range stats { diff --git a/internal/webrtc/metrics.go b/internal/webrtc/metrics.go index b682b070..bd377294 100644 --- a/internal/webrtc/metrics.go +++ b/internal/webrtc/metrics.go @@ -17,8 +17,10 @@ type metrics struct { iceCandidates map[string]struct{} iceCandidatesCount prometheus.Counter - bytesSent prometheus.Gauge - bytesReceived prometheus.Gauge + iceBytesSent prometheus.Gauge + iceBytesReceived prometheus.Gauge + sctpBytesSent prometheus.Gauge + sctpBytesReceived prometheus.Gauge } type metricsCtx struct { @@ -82,20 +84,39 @@ func (m *metricsCtx) getBySession(session types.Session) metrics { }, }), - bytesSent: promauto.NewGauge(prometheus.GaugeOpts{ - Name: "bytes_sent", + iceBytesSent: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "ice_bytes_sent", Namespace: "neko", Subsystem: "webrtc", - Help: "Sent bytes to a session.", + Help: "Sent bytes using ICE transport to a session.", ConstLabels: map[string]string{ "session_id": session.ID(), }, }), - bytesReceived: promauto.NewGauge(prometheus.GaugeOpts{ - Name: "bytes_received", + iceBytesReceived: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "ice_bytes_received", Namespace: "neko", Subsystem: "webrtc", - Help: "Received bytes from a session.", + Help: "Received bytes using ICE transport from a session.", + ConstLabels: map[string]string{ + "session_id": session.ID(), + }, + }), + + sctpBytesSent: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "sctp_bytes_sent", + Namespace: "neko", + Subsystem: "webrtc", + Help: "Sent bytes using SCTP transport to a session.", + ConstLabels: map[string]string{ + "session_id": session.ID(), + }, + }), + sctpBytesReceived: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "sctp_bytes_received", + Namespace: "neko", + Subsystem: "webrtc", + Help: "Received bytes using SCTP transport from a session.", ConstLabels: map[string]string{ "session_id": session.ID(), }, @@ -145,9 +166,16 @@ func (m *metricsCtx) SetState(session types.Session, state webrtc.PeerConnection met.connectionStateCount.Add(1) } -func (m *metricsCtx) SetTransportStats(session types.Session, data webrtc.TransportStats) { +func (m *metricsCtx) SetIceTransportStats(session types.Session, data webrtc.TransportStats) { met := m.getBySession(session) - met.bytesSent.Set(float64(data.BytesSent)) - met.bytesReceived.Set(float64(data.BytesReceived)) + met.iceBytesSent.Set(float64(data.BytesSent)) + met.iceBytesReceived.Set(float64(data.BytesReceived)) +} + +func (m *metricsCtx) SetSctpTransportStats(session types.Session, data webrtc.TransportStats) { + met := m.getBySession(session) + + met.sctpBytesSent.Set(float64(data.BytesSent)) + met.sctpBytesReceived.Set(float64(data.BytesReceived)) }