2022-03-10 09:44:48 +00:00
|
|
|
package ice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetCandidatePairsStats returns a list of candidate pair stats
|
|
|
|
func (a *Agent) GetCandidatePairsStats() []CandidatePairStats {
|
|
|
|
var res []CandidatePairStats
|
|
|
|
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
|
|
|
|
result := make([]CandidatePairStats, 0, len(agent.checklist))
|
|
|
|
for _, cp := range agent.checklist {
|
|
|
|
stat := CandidatePairStats{
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
LocalCandidateID: cp.Local.ID(),
|
|
|
|
RemoteCandidateID: cp.Remote.ID(),
|
|
|
|
State: cp.state,
|
|
|
|
Nominated: cp.nominated,
|
|
|
|
// PacketsSent uint32
|
|
|
|
// PacketsReceived uint32
|
|
|
|
// BytesSent uint64
|
|
|
|
// BytesReceived uint64
|
|
|
|
// LastPacketSentTimestamp time.Time
|
|
|
|
// LastPacketReceivedTimestamp time.Time
|
|
|
|
// FirstRequestTimestamp time.Time
|
|
|
|
// LastRequestTimestamp time.Time
|
|
|
|
// LastResponseTimestamp time.Time
|
|
|
|
// TotalRoundTripTime float64
|
|
|
|
// CurrentRoundTripTime float64
|
|
|
|
// AvailableOutgoingBitrate float64
|
|
|
|
// AvailableIncomingBitrate float64
|
|
|
|
// CircuitBreakerTriggerCount uint32
|
|
|
|
// RequestsReceived uint64
|
|
|
|
// RequestsSent uint64
|
|
|
|
// ResponsesReceived uint64
|
|
|
|
// ResponsesSent uint64
|
|
|
|
// RetransmissionsReceived uint64
|
|
|
|
// RetransmissionsSent uint64
|
|
|
|
// ConsentRequestsSent uint64
|
|
|
|
// ConsentExpiredTimestamp time.Time
|
|
|
|
}
|
|
|
|
result = append(result, stat)
|
|
|
|
}
|
|
|
|
res = result
|
|
|
|
})
|
|
|
|
if err != nil {
|
2024-01-18 18:54:54 +00:00
|
|
|
a.log.Errorf("error getting candidate pairs stats %v", err)
|
2022-03-10 09:44:48 +00:00
|
|
|
return []CandidatePairStats{}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLocalCandidatesStats returns a list of local candidates stats
|
|
|
|
func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
|
|
|
|
var res []CandidateStats
|
|
|
|
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
|
|
|
|
result := make([]CandidateStats, 0, len(agent.localCandidates))
|
|
|
|
for networkType, localCandidates := range agent.localCandidates {
|
|
|
|
for _, c := range localCandidates {
|
|
|
|
relayProtocol := ""
|
|
|
|
if c.Type() == CandidateTypeRelay {
|
2024-01-18 18:54:54 +00:00
|
|
|
relayProtocol = c.(*CandidateRelay).RelayProtocol()
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
stat := CandidateStats{
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: c.ID(),
|
|
|
|
NetworkType: networkType,
|
|
|
|
IP: c.Address(),
|
|
|
|
Port: c.Port(),
|
|
|
|
CandidateType: c.Type(),
|
|
|
|
Priority: c.Priority(),
|
|
|
|
// URL string
|
|
|
|
RelayProtocol: relayProtocol,
|
|
|
|
// Deleted bool
|
|
|
|
}
|
|
|
|
result = append(result, stat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = result
|
|
|
|
})
|
|
|
|
if err != nil {
|
2024-01-18 18:54:54 +00:00
|
|
|
a.log.Errorf("error getting candidate pairs stats %v", err)
|
2022-03-10 09:44:48 +00:00
|
|
|
return []CandidateStats{}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRemoteCandidatesStats returns a list of remote candidates stats
|
|
|
|
func (a *Agent) GetRemoteCandidatesStats() []CandidateStats {
|
|
|
|
var res []CandidateStats
|
|
|
|
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
|
|
|
|
result := make([]CandidateStats, 0, len(agent.remoteCandidates))
|
2024-01-18 18:54:54 +00:00
|
|
|
for networkType, localCandidates := range agent.remoteCandidates {
|
|
|
|
for _, c := range localCandidates {
|
2022-03-10 09:44:48 +00:00
|
|
|
stat := CandidateStats{
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: c.ID(),
|
|
|
|
NetworkType: networkType,
|
|
|
|
IP: c.Address(),
|
|
|
|
Port: c.Port(),
|
|
|
|
CandidateType: c.Type(),
|
|
|
|
Priority: c.Priority(),
|
|
|
|
// URL string
|
|
|
|
RelayProtocol: "",
|
|
|
|
}
|
|
|
|
result = append(result, stat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = result
|
|
|
|
})
|
|
|
|
if err != nil {
|
2024-01-18 18:54:54 +00:00
|
|
|
a.log.Errorf("error getting candidate pairs stats %v", err)
|
2022-03-10 09:44:48 +00:00
|
|
|
return []CandidateStats{}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|