Add prom histogram for forwarding latency and jitter. (#4044)

* Add prom histogram for forwarding latency and jitter.

Using short term stats for histogram.

An example setting is
1s - short term
1m - long term

Using the 1s (short term) data for histogram. In that 1 second, all
packet forwarding latencies are averaged for latency and std. dev. of
the collection is used as jitter.

* try different staticcheck
This commit is contained in:
Raja Subramanian
2025-11-01 23:25:03 +05:30
committed by GitHub
parent 1eefeb3089
commit e183657cff
2 changed files with 30 additions and 9 deletions

View File

@@ -35,7 +35,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '^1.24'
go-version: "^1.24"
- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.4.1
@@ -57,7 +57,7 @@ jobs:
args: build
- name: Static Check
uses: amarpal/staticcheck-action@master
uses: dominikh/staticcheck-action@v1
with:
checks: '["all", "-ST1000", "-ST1003", "-ST1020", "-ST1021", "-ST1022", "-SA1019"]'
install-go: false

View File

@@ -67,6 +67,8 @@ var (
promConnections *prometheus.GaugeVec
promForwardLatency prometheus.Gauge
promForwardJitter prometheus.Gauge
promForwardLatencyHist prometheus.Histogram
promForwardJitterHist prometheus.Histogram
promPacketTotalIncomingInitial prometheus.Counter
promPacketTotalIncomingRetransmit prometheus.Counter
@@ -140,7 +142,6 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
Subsystem: "jitter",
Name: "us",
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
// 1ms, 10ms, 30ms, 50ms, 70ms, 100ms, 300ms, 600ms, 1s
Buckets: []float64{1000, 10000, 30000, 50000, 70000, 100000, 300000, 600000, 1000000},
}, promStreamLabels)
@@ -175,6 +176,22 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
Name: "jitter",
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
})
promForwardLatencyHist = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: livekitNamespace,
Subsystem: "forward_latency",
Name: "ns",
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
// 1ms, 2ms, 3ms, 4ms, 5ms, 10ms, 20ms
Buckets: []float64{1000, 2000, 3000, 4000, 5000, 10000, 20000},
})
promForwardJitterHist = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: livekitNamespace,
Subsystem: "forward_jitter",
Name: "ns",
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
// 1ms, 2ms, 3ms, 4ms, 5ms, 10ms, 20ms
Buckets: []float64{1000, 2000, 3000, 4000, 5000, 10000, 20000},
})
prometheus.MustRegister(promPacketTotal)
prometheus.MustRegister(promPacketBytes)
@@ -191,6 +208,8 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
prometheus.MustRegister(promConnections)
prometheus.MustRegister(promForwardLatency)
prometheus.MustRegister(promForwardJitter)
prometheus.MustRegister(promForwardLatencyHist)
prometheus.MustRegister(promForwardJitterHist)
}
func IncrementPackets(country string, direction Direction, count uint64, retransmit bool) {
@@ -316,12 +335,14 @@ func SubConnection(direction Direction) {
promConnections.WithLabelValues(string(direction)).Sub(1)
}
func RecordForwardLatency(_, latencyAvg uint32) {
forwardLatency.Store(latencyAvg)
promForwardLatency.Set(float64(latencyAvg))
func RecordForwardLatency(shortTermLatencyAvg, longTermLatencyAvg uint32) {
forwardLatency.Store(longTermLatencyAvg)
promForwardLatency.Set(float64(longTermLatencyAvg))
promForwardLatencyHist.Observe(float64(shortTermLatencyAvg))
}
func RecordForwardJitter(_, jitterAvg uint32) {
forwardJitter.Store(jitterAvg)
promForwardJitter.Set(float64(jitterAvg))
func RecordForwardJitter(shortTermJitterAvg, longTermJitterAvg uint32) {
forwardJitter.Store(longTermJitterAvg)
promForwardJitter.Set(float64(longTermJitterAvg))
promForwardJitterHist.Observe(float64(shortTermJitterAvg))
}