Add metrics for candidates and ICE, DTLS and PeerConnection states.

This commit is contained in:
Joachim Bauch 2025-11-06 20:41:43 +01:00
commit fa900132b4
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
3 changed files with 51 additions and 1 deletions

View file

@ -60,3 +60,8 @@ The following metrics are available:
| `signaling_mcu_backend_bandwidth` | Gauge | 2.0.5 | The current bandwidth of signaling proxy backends in bytes per second | `url`, `direction` |
| `signaling_proxy_load` | Gauge | 2.0.5 | The current load of the signaling proxy | |
| `signaling_client_rtt` | Histogram | 2.0.5 | The roundtrip time of WebSocket ping messages in milliseconds | |
| `signaling_mcu_selected_local_candidate_total` | Counter | 2.0.5 | Total number of selected local candidates | `type`, `transport`, `family` |
| `signaling_mcu_selected_remote_candidate_total` | Counter | 2.0.5 | Total number of selected local candidates | `type`, `transport`, `family` |
| `signaling_mcu_peerconnection_state_total` | Counter | 2.0.5 | Total number PeerConnection states | `state`, `reason` |
| `signaling_mcu_ice_state_total` | Counter | 2.0.5 | Total number of ICE connection states | `state` |
| `signaling_mcu_dtls_state_total` | Counter | 2.0.5 | Total number of DTLS connection states | `state` |

View file

@ -302,7 +302,8 @@ func (e JanusEventWebRTCDTLS) String() string {
// type=16, subtype=6
type JanusEventWebRTCPeerConnection struct {
Connection string `json:"connection"` // "webrtcup"
Connection string `json:"connection"` // "webrtcup", "hangup"
Reason string `json:"reason,omitempty"` // Only if "connection" == "hangup"
}
func (e JanusEventWebRTCPeerConnection) String() string {
@ -737,6 +738,15 @@ func (h *JanusEventsHandler) processEvent(event JanusEvent) {
}
switch evt := evt.(type) {
case *JanusEventWebRTCICE:
statsJanusICEStateTotal.WithLabelValues(evt.ICE).Inc()
case *JanusEventWebRTCDTLS:
statsJanusDTLSStateTotal.WithLabelValues(evt.DTLS).Inc()
case *JanusEventWebRTCPeerConnection:
statsJanusPeerConnectionStateTotal.WithLabelValues(evt.Connection, evt.Reason).Inc()
case *JanusEventWebRTCSelectedPair:
statsJanusSelectedLocalCandidateTotal.WithLabelValues(evt.Candidates.Local.Type, evt.Candidates.Local.Transport, fmt.Sprintf("ipv%d", evt.Candidates.Local.Family)).Inc()
statsJanusSelectedRemoteCandidateTotal.WithLabelValues(evt.Candidates.Remote.Type, evt.Candidates.Remote.Transport, fmt.Sprintf("ipv%d", evt.Candidates.Remote.Family)).Inc()
case *JanusEventMediaStats:
h.mcu.UpdateBandwidth(event.HandleId, evt.Media, api.BandwidthFromBytes(uint64(evt.BytesSentLastSec)), api.BandwidthFromBytes(uint64(evt.BytesReceivedLastSec)))
}

View file

@ -92,9 +92,44 @@ var (
Name: "bandwidth",
Help: "The current bandwidth in bytes per second",
}, []string{"direction"})
statsJanusSelectedLocalCandidateTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "mcu",
Name: "selected_local_candidate_total",
Help: "Total number of selected local candidates",
}, []string{"type", "transport", "family"})
statsJanusSelectedRemoteCandidateTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "mcu",
Name: "selected_remote_candidate_total",
Help: "Total number of selected remote candidates",
}, []string{"type", "transport", "family"})
statsJanusPeerConnectionStateTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "mcu",
Name: "peerconnection_state_total",
Help: "Total number of PeerConnections states",
}, []string{"state", "reason"})
statsJanusICEStateTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "mcu",
Name: "ice_state_total",
Help: "Total number of ICE connection states",
}, []string{"state"})
statsJanusDTLSStateTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "mcu",
Name: "dtls_state_total",
Help: "Total number of DTLS connection states",
}, []string{"state"})
janusMcuStats = []prometheus.Collector{
statsJanusBandwidthCurrent,
statsJanusSelectedLocalCandidateTotal,
statsJanusSelectedRemoteCandidateTotal,
statsJanusPeerConnectionStateTotal,
statsJanusICEStateTotal,
statsJanusDTLSStateTotal,
}
statsConnectedProxyBackendsCurrent = prometheus.NewGaugeVec(prometheus.GaugeOpts{