Candidate Pair Statistics
The primary statistics interface provides detailed metrics for candidate pairs:stats.go
Getting Statistics
All Candidate Pairs
Retrieve statistics for all candidate pairs in the checklist:Selected Candidate Pair
Get statistics for only the currently selected (nominated) pair:GetSelectedCandidatePairStats returns false if no pair has been nominated yet. Check the boolean return value before accessing statistics.Candidate Statistics
Get information about individual local or remote candidates:stats.go
Local Candidates
Remote Candidates
Monitoring Connection Quality
Real-Time RTT Monitoring
Bandwidth Estimation
Average RTT Calculation
Calculate average RTT from total measurements:Connection Activity Tracking
Detect idle connections or stalled traffic:Diagnostic Report
Generate a comprehensive diagnostic report:Metrics Export
Export statistics in structured format for monitoring systems:STUN Request/Response Analysis
Monitor connectivity check patterns:Thread Safety
All statistics methods are thread-safe. They use the agent’s internal event loop to safely access state, so you can call them from any goroutine without additional synchronization.
agent_stats.go
Best Practices
Polling Frequency
Polling Frequency
Balance between visibility and performance:
- Selected pair monitoring: Every 1-5 seconds for connection quality
- All pairs: Every 10-30 seconds for detailed analysis
- Candidates: Once per gathering phase or on demand
Memory Considerations
Memory Considerations
Statistics methods return copies of data, not references:For high-frequency monitoring, reuse buffers or limit scope:
Interpreting RTT Values
Interpreting RTT Values
- CurrentRoundTripTime: Latest measurement, subject to variance
- TotalRoundTripTime / ResponsesReceived: Average, more stable
Detecting Network Changes
Detecting Network Changes
Monitor for patterns indicating network issues:
- Sudden RTT increase (>2x previous)
- Zero packets received for >10 seconds
- STUN response rate drops below 50%
- Bytes sent/received stops incrementing
Reference
- Candidate Pair Stats:
stats.go:10- CandidatePairStats type definition - Candidate Stats:
stats.go:170- CandidateStats type definition - Agent Methods:
agent_stats.go:12- GetCandidatePairsStats, GetSelectedCandidatePairStats - Pair Info:
stats.go:143- CandidatePairInfo for renomination