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:
@@ -35,7 +35,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '^1.24'
|
go-version: "^1.24"
|
||||||
|
|
||||||
- name: Set up gotestfmt
|
- name: Set up gotestfmt
|
||||||
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.4.1
|
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@v2.4.1
|
||||||
@@ -57,7 +57,7 @@ jobs:
|
|||||||
args: build
|
args: build
|
||||||
|
|
||||||
- name: Static Check
|
- name: Static Check
|
||||||
uses: amarpal/staticcheck-action@master
|
uses: dominikh/staticcheck-action@v1
|
||||||
with:
|
with:
|
||||||
checks: '["all", "-ST1000", "-ST1003", "-ST1020", "-ST1021", "-ST1022", "-SA1019"]'
|
checks: '["all", "-ST1000", "-ST1003", "-ST1020", "-ST1021", "-ST1022", "-SA1019"]'
|
||||||
install-go: false
|
install-go: false
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ var (
|
|||||||
promConnections *prometheus.GaugeVec
|
promConnections *prometheus.GaugeVec
|
||||||
promForwardLatency prometheus.Gauge
|
promForwardLatency prometheus.Gauge
|
||||||
promForwardJitter prometheus.Gauge
|
promForwardJitter prometheus.Gauge
|
||||||
|
promForwardLatencyHist prometheus.Histogram
|
||||||
|
promForwardJitterHist prometheus.Histogram
|
||||||
|
|
||||||
promPacketTotalIncomingInitial prometheus.Counter
|
promPacketTotalIncomingInitial prometheus.Counter
|
||||||
promPacketTotalIncomingRetransmit prometheus.Counter
|
promPacketTotalIncomingRetransmit prometheus.Counter
|
||||||
@@ -140,7 +142,6 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
|
|||||||
Subsystem: "jitter",
|
Subsystem: "jitter",
|
||||||
Name: "us",
|
Name: "us",
|
||||||
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
|
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
|
||||||
|
|
||||||
// 1ms, 10ms, 30ms, 50ms, 70ms, 100ms, 300ms, 600ms, 1s
|
// 1ms, 10ms, 30ms, 50ms, 70ms, 100ms, 300ms, 600ms, 1s
|
||||||
Buckets: []float64{1000, 10000, 30000, 50000, 70000, 100000, 300000, 600000, 1000000},
|
Buckets: []float64{1000, 10000, 30000, 50000, 70000, 100000, 300000, 600000, 1000000},
|
||||||
}, promStreamLabels)
|
}, promStreamLabels)
|
||||||
@@ -175,6 +176,22 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
|
|||||||
Name: "jitter",
|
Name: "jitter",
|
||||||
ConstLabels: prometheus.Labels{"node_id": nodeID, "node_type": nodeType.String()},
|
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(promPacketTotal)
|
||||||
prometheus.MustRegister(promPacketBytes)
|
prometheus.MustRegister(promPacketBytes)
|
||||||
@@ -191,6 +208,8 @@ func initPacketStats(nodeID string, nodeType livekit.NodeType) {
|
|||||||
prometheus.MustRegister(promConnections)
|
prometheus.MustRegister(promConnections)
|
||||||
prometheus.MustRegister(promForwardLatency)
|
prometheus.MustRegister(promForwardLatency)
|
||||||
prometheus.MustRegister(promForwardJitter)
|
prometheus.MustRegister(promForwardJitter)
|
||||||
|
prometheus.MustRegister(promForwardLatencyHist)
|
||||||
|
prometheus.MustRegister(promForwardJitterHist)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IncrementPackets(country string, direction Direction, count uint64, retransmit bool) {
|
func IncrementPackets(country string, direction Direction, count uint64, retransmit bool) {
|
||||||
@@ -316,12 +335,14 @@ func SubConnection(direction Direction) {
|
|||||||
promConnections.WithLabelValues(string(direction)).Sub(1)
|
promConnections.WithLabelValues(string(direction)).Sub(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RecordForwardLatency(_, latencyAvg uint32) {
|
func RecordForwardLatency(shortTermLatencyAvg, longTermLatencyAvg uint32) {
|
||||||
forwardLatency.Store(latencyAvg)
|
forwardLatency.Store(longTermLatencyAvg)
|
||||||
promForwardLatency.Set(float64(latencyAvg))
|
promForwardLatency.Set(float64(longTermLatencyAvg))
|
||||||
|
promForwardLatencyHist.Observe(float64(shortTermLatencyAvg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RecordForwardJitter(_, jitterAvg uint32) {
|
func RecordForwardJitter(shortTermJitterAvg, longTermJitterAvg uint32) {
|
||||||
forwardJitter.Store(jitterAvg)
|
forwardJitter.Store(longTermJitterAvg)
|
||||||
promForwardJitter.Set(float64(jitterAvg))
|
promForwardJitter.Set(float64(longTermJitterAvg))
|
||||||
|
promForwardJitterHist.Observe(float64(shortTermJitterAvg))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user