diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index 7bf18d41..cc8523a9 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -404,6 +404,13 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin switch rtcpPacket := p.(type) { case *rtcp.ReceiverEstimatedMaximumBitrate: // TODO: Deprecated. manager.metrics.SetReceiverEstimatedMaximumBitrate(session, rtcpPacket.Bitrate) + + case *rtcp.ReceiverReport: + l := len(rtcpPacket.Reports) + if l > 0 { + // use only last report + manager.metrics.SetReceiverReport(session, rtcpPacket.Reports[l-1]) + } } }) diff --git a/internal/webrtc/metrics.go b/internal/webrtc/metrics.go index c386e0d3..8c1f4143 100644 --- a/internal/webrtc/metrics.go +++ b/internal/webrtc/metrics.go @@ -3,6 +3,7 @@ package webrtc import ( "sync" + "github.com/pion/rtcp" "github.com/pion/webrtc/v3" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -23,6 +24,10 @@ type metrics struct { receiverEstimatedMaximumBitrate prometheus.Gauge + receiverReportDelay prometheus.Gauge + receiverReportJitter prometheus.Gauge + receiverReportTotalLost prometheus.Gauge + iceBytesSent prometheus.Gauge iceBytesReceived prometheus.Gauge sctpBytesSent prometheus.Gauge @@ -104,6 +109,34 @@ func (m *metricsCtx) getBySession(session types.Session) metrics { }, }), + receiverReportDelay: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "receiver_report_delay", + Namespace: "neko", + Subsystem: "webrtc", + Help: "Receiver Report Delay from SCTP, expressed in units of 1/65536 seconds.", + ConstLabels: map[string]string{ + "session_id": session.ID(), + }, + }), + receiverReportJitter: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "receiver_report_jitter", + Namespace: "neko", + Subsystem: "webrtc", + Help: "Receiver Report Jitter from SCTP.", + ConstLabels: map[string]string{ + "session_id": session.ID(), + }, + }), + receiverReportTotalLost: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "receiver_report_total_lost", + Namespace: "neko", + Subsystem: "webrtc", + Help: "Receiver Report Total Lost from SCTP.", + ConstLabels: map[string]string{ + "session_id": session.ID(), + }, + }), + iceBytesSent: promauto.NewGauge(prometheus.GaugeOpts{ Name: "bytes_sent", Namespace: "neko", @@ -227,6 +260,14 @@ func (m *metricsCtx) SetReceiverEstimatedMaximumBitrate(session types.Session, b met.receiverEstimatedMaximumBitrate.Set(float64(bitrate)) } +func (m *metricsCtx) SetReceiverReport(session types.Session, report rtcp.ReceptionReport) { + met := m.getBySession(session) + + met.receiverReportDelay.Set(float64(report.Delay)) + met.receiverReportJitter.Set(float64(report.Jitter)) + met.receiverReportTotalLost.Set(float64(report.TotalLost)) +} + func (m *metricsCtx) SetIceTransportStats(session types.Session, data webrtc.TransportStats) { met := m.getBySession(session)