turn packet and bytes stats used for telemetry and load control (#969)

* stats for turn

* add connections stats

* stats for standalone turn server only

* wire update
This commit is contained in:
cnderrauber
2022-08-31 11:00:27 +08:00
committed by GitHub
parent df189984f3
commit c401ca58af
5 changed files with 161 additions and 4 deletions
+16
View File
@@ -32,6 +32,7 @@ var (
promPliTotal *prometheus.CounterVec
promFirTotal *prometheus.CounterVec
promParticipantJoin *prometheus.CounterVec
promConnections *prometheus.GaugeVec
)
func initPacketStats(nodeID string) {
@@ -71,6 +72,12 @@ func initPacketStats(nodeID string) {
Name: "total",
ConstLabels: prometheus.Labels{"node_id": nodeID},
}, nil)
promConnections = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: livekitNamespace,
Subsystem: "connection",
Name: "total",
ConstLabels: prometheus.Labels{"node_id": nodeID},
}, []string{"kind"})
prometheus.MustRegister(promPacketTotal)
prometheus.MustRegister(promPacketBytes)
@@ -78,6 +85,7 @@ func initPacketStats(nodeID string) {
prometheus.MustRegister(promPliTotal)
prometheus.MustRegister(promFirTotal)
prometheus.MustRegister(promParticipantJoin)
prometheus.MustRegister(promConnections)
}
func IncrementPackets(direction Direction, count uint64, retransmit bool) {
@@ -130,6 +138,14 @@ func IncrementParticipantJoin(join uint32) {
}
}
func AddConnection(direction Direction) {
promConnections.WithLabelValues(string(direction)).Add(1)
}
func SubConnection(direction Direction) {
promConnections.WithLabelValues(string(direction)).Sub(1)
}
func transmissionLabel(retransmit bool) string {
if !retransmit {
return transmissionInitial