From 71fda2f258024ea79d5b4d94f6d77eab76f6ba06 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Thu, 6 Nov 2025 16:35:54 +0100 Subject: [PATCH] Add metric for RTT of WebSocket ping messages. --- client.go | 1 + client_stats_prometheus.go | 8 ++++++++ docs/prometheus-metrics.md | 1 + 3 files changed, 10 insertions(+) diff --git a/client.go b/client.go index 53f8967..b7d7d38 100644 --- a/client.go +++ b/client.go @@ -353,6 +353,7 @@ func (c *Client) ReadPump() { log.Printf("Client from %s has RTT of %d ms (%s)", addr, rtt_ms, rtt) } } + statsClientRTT.Observe(float64(rtt.Milliseconds())) c.getHandler().OnRTTReceived(c, rtt) } return nil diff --git a/client_stats_prometheus.go b/client_stats_prometheus.go index e20447e..6a6d140 100644 --- a/client_stats_prometheus.go +++ b/client_stats_prometheus.go @@ -32,9 +32,17 @@ var ( Name: "countries_total", Help: "The total number of connections by country", }, []string{"country"}) + statsClientRTT = prometheus.NewHistogram(prometheus.HistogramOpts{ + Namespace: "signaling", + Subsystem: "client", + Name: "rtt", + Help: "The roundtrip time of WebSocket ping messages in milliseconds", + Buckets: prometheus.ExponentialBucketsRange(1, 30000, 50), + }) clientStats = []prometheus.Collector{ statsClientCountries, + statsClientRTT, } ) diff --git a/docs/prometheus-metrics.md b/docs/prometheus-metrics.md index 1f1c155..013c601 100644 --- a/docs/prometheus-metrics.md +++ b/docs/prometheus-metrics.md @@ -59,3 +59,4 @@ The following metrics are available: | `signaling_mcu_backend_usage` | Gauge | 2.0.5 | The current usage of signaling proxy backends in percent | `url`, `direction` | | `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 | |