webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

Implement PeerConnection GetStats API

Open maxhawkins opened this issue 5 years ago • 11 comments

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)

maxhawkins avatar Apr 10 '19 17:04 maxhawkins

any updates?

xsbchen avatar May 14 '19 04:05 xsbchen

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.

maxhawkins avatar May 15 '19 15:05 maxhawkins

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

maxhawkins avatar Jun 27 '19 16:06 maxhawkins

@Sean-Der @hugoArregui is there any more pending work on this ticket?

enobufs avatar Aug 11 '19 19:08 enobufs

Yes, a lot, there are missing stats and some missing fields from the implemented ones

hugoArregui avatar Aug 11 '19 19:08 hugoArregui

Is there a grand master plan behind putting json keys in the stats structs?

somersbmatthews avatar Jul 28 '20 09:07 somersbmatthews

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 avatar Jul 29 '20 20:07 maxhawkins

@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 :)

somersbmatthews avatar Jul 29 '20 21:07 somersbmatthews

@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.

somersbmatthews avatar Jul 29 '20 21:07 somersbmatthews

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.

maxhawkins avatar Jul 29 '20 21:07 maxhawkins

Hi, is there any plan to work on this ticket?

hiteshgarg14 avatar Jan 14 '23 16:01 hiteshgarg14

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.

Sean-Der avatar Apr 04 '24 03:04 Sean-Der