mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add video id for webrtc metrics.
This commit is contained in:
parent
e4261c53b1
commit
3fda00bac5
@ -138,6 +138,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
return nil, types.ErrWebRTCVideoNotFound
|
||||
}
|
||||
|
||||
manager.metrics.SetVideoID(session, videoID)
|
||||
|
||||
connection, err := manager.newPeerConnection([]codec.RTPCodec{
|
||||
audioStream.Codec(),
|
||||
videoStream.Codec(),
|
||||
@ -201,6 +203,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
return types.ErrWebRTCVideoNotFound
|
||||
}
|
||||
|
||||
manager.metrics.SetVideoID(session, videoID)
|
||||
return videoTrack.SetStream(videoStream)
|
||||
},
|
||||
setPaused: func(isPaused bool) {
|
||||
|
@ -18,6 +18,9 @@ type metrics struct {
|
||||
iceCandidatesMu *sync.Mutex
|
||||
iceCandidatesCount prometheus.Counter
|
||||
|
||||
videoIds map[string]prometheus.Gauge
|
||||
videoIdsMu *sync.Mutex
|
||||
|
||||
iceBytesSent prometheus.Gauge
|
||||
iceBytesReceived prometheus.Gauge
|
||||
sctpBytesSent prometheus.Gauge
|
||||
@ -86,6 +89,9 @@ func (m *metricsCtx) getBySession(session types.Session) metrics {
|
||||
},
|
||||
}),
|
||||
|
||||
videoIds: map[string]prometheus.Gauge{},
|
||||
videoIdsMu: &sync.Mutex{},
|
||||
|
||||
iceBytesSent: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "ice_bytes_sent",
|
||||
Namespace: "neko",
|
||||
@ -171,6 +177,34 @@ func (m *metricsCtx) SetState(session types.Session, state webrtc.PeerConnection
|
||||
met.connectionStateCount.Add(1)
|
||||
}
|
||||
|
||||
func (m *metricsCtx) SetVideoID(session types.Session, videoId string) {
|
||||
met := m.getBySession(session)
|
||||
|
||||
met.videoIdsMu.Lock()
|
||||
defer met.videoIdsMu.Unlock()
|
||||
|
||||
if _, found := met.videoIds[videoId]; !found {
|
||||
met.videoIds[videoId] = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "video_id",
|
||||
Namespace: "neko",
|
||||
Subsystem: "webrtc",
|
||||
Help: "Current Video ID of a session.",
|
||||
ConstLabels: map[string]string{
|
||||
"session_id": session.ID(),
|
||||
"video_id": videoId,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
for id, entry := range met.videoIds {
|
||||
if id == videoId {
|
||||
entry.Set(1)
|
||||
} else {
|
||||
entry.Set(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *metricsCtx) SetIceTransportStats(session types.Session, data webrtc.TransportStats) {
|
||||
met := m.getBySession(session)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user