webrtc
webrtc copied to clipboard
Implement PeerConnection GetStats API
Summary
Add support for the PeerConnection GetStats method, conforming to the dom-rtcstats spec.
Motivation
Exposing this API makes it easier to debug connection problems by exposing statistics on lower-level components of the API. Using this standard format will allow our implementation to be interoperable with stats analysis tooling created for the browser's getStats method.
Mandatory Stats
An implementation MUST support generating statistics of the following types when the corresponding objects exist on a PeerConnection, with the attributes that are listed when they are valid for that object:
- [ ]
RTCRTPStreamStats
- [ ]
RTCReceivedRTPStreamStats
- [ ]
RTCInboundRTPStreamStats
- [ ]
RTCRemoteInboundRTPStreamStats
- [ ]
RTCSentRTPStreamStats
- [ ]
RTCOutboundRTPStreamStats
- [ ]
RTCRemoteOutboundRTPStreamStats
- [x]
RTCPeerConnectionStats
- [x]
RTCDataChannelStats
- [ ]
RTCMediaStreamStats
- [ ]
RTCMediaStreamTrackStats
- [ ]
RTCMediaHandlerStats
- [ ]
RTCAudioHandlerStats
- [ ]
RTCVideoHandlerStats
- [ ]
RTCVideoSenderStats
- [ ]
RTCVideoReceiverStats
- [x]
RTCCodecStats
- [ ]
RTCTransportStats
- [x]
RTCIceCandidatePairStats
- [x]
RTCIceCandidateStats
- [x]
RTCCertificateStats
Missing attributes on implemented stats
The fields are there, but they are not actually properly loaded
RTCICECandidatePairStats
- [ ] PacketsSent
- [ ] PacketsReceived
- [ ] BytesSent
- [ ] BytesReceived
- [ ] LastPacketSentTimestamp
- [ ] LastPacketReceivedTimestamp
- [ ] FirstRequestTimestamp
- [ ] LastRequestTimestamp
- [ ] LastResponseTimestamp
- [ ] TotalRoundTripTime
- [ ] CurrentRoundTripTime
- [ ] AvailableOutgoingBitrate
- [ ] AvailableIncomingBitrate
- [ ] CircuitBreakerTriggerCount
- [ ] RequestsReceived
- [ ] RequestsSent
- [ ] ResponsesReceived
- [ ] ResponsesSent
- [ ] RetransmissionsReceived
- [ ] RetransmissionsSent
- [ ] ConsentRequestsSent
- [ ] ConsentExpiredTimestamp
RTCIceCandidateStats
- [ ] URL
- [ ] Deleted (for local candidates only)
any updates?
I got pulled away to another project so I'm not working on this currently, unfortunately.
If you want to take a stab at wiring up some of the structs I'd be happy to do a code review.
Work has started on this. Thank you @hugoArregui!
Only RTCPeerConnectionStats
, RTCIceCandidatePairStats
, and RTCIceCandidateStats
are implemented at the moment. We're looking for help implementing the other stat types.
Here's the commit adding GetStats: https://github.com/pion/webrtc/commit/93261960b1c10359cfeef337a0710c4b0ce3c8a6
@Sean-Der @hugoArregui is there any more pending work on this ticket?
Yes, a lot, there are missing stats and some missing fields from the implemented ones
Is there a grand master plan behind putting json keys in the stats structs?
Is there a grand master plan behind putting json keys in the stats structs?
It makes it possible to deserialize JSON-encoded stats data from the browser.
@maxhawkins I use go-metrics packages like https://github.com/armon/go-metrics that make their own json with metrics. I know there are things like this: https://github.com/project-sunbird/prometheus-jsonpath-exporter. I was just curious how one is supposed to go about using the pion stats json in a front-end. Is the user supposed to hard code a front-end to show the json or use prometheus with graphana or something? thanks :)
@maxhawkins Like, if there were an example of how to use these webrtc stats metrics json, how would it show how to use the json to see your webrtc stats. That's what I'm getting at.
Since dom-rtcstats is now standardized every browser implementation of WebRTC should export getStats()
in a format compatible with Pion. The PR above implements the rtcstats spec.
You can decode using the json package and then do whatever you like with it—send it to prometheus, store in in Postgres, etc.
Hi, is there any plan to work on this ticket?
Hi @hiteshgarg14
I think this is a task that will never be done. It can always be better. I am resolving since we don't have anything actionable out of this.