From 889ec056f21e6f8f5dc01f15783fa4986f314995 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 5 Nov 2025 12:11:13 +0100 Subject: [PATCH] Also expose bandwidth usage of backend servers through metrics. --- api_proxy.go | 5 +++++ docs/prometheus-metrics.md | 1 + mcu_proxy.go | 6 ++++++ mcu_stats_prometheus.go | 7 +++++++ proxy/proxy_server.go | 8 ++++++-- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api_proxy.go b/api_proxy.go index 8f3bd6e..7b1a5e7 100644 --- a/api_proxy.go +++ b/api_proxy.go @@ -321,6 +321,11 @@ type EventProxyServerBandwidth struct { Incoming *float64 `json:"incoming,omitempty"` // Outgoing is the bandwidth utilization for subscribers in percent. Outgoing *float64 `json:"outgoing,omitempty"` + + // Received is the incoming bandwidth in bytes per second. + Received uint64 `json:"received,omitempty"` + // Sent is the outgoing bandwidth in bytes per second. + Sent uint64 `json:"sent,omitempty"` } func (b *EventProxyServerBandwidth) String() string { diff --git a/docs/prometheus-metrics.md b/docs/prometheus-metrics.md index 5027c40..1f1c155 100644 --- a/docs/prometheus-metrics.md +++ b/docs/prometheus-metrics.md @@ -57,4 +57,5 @@ The following metrics are available: | `signaling_backend_client_requests_errors_total` | Counter | 2.0.3 | The total number of backend client requests that had an error | `backend`, `error` | | `signaling_mcu_bandwidth` | Gauge | 2.0.5 | The current bandwidth in bytes per second | `direction` | | `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 | | diff --git a/mcu_proxy.go b/mcu_proxy.go index 461be23..b46d703 100644 --- a/mcu_proxy.go +++ b/mcu_proxy.go @@ -416,6 +416,8 @@ func newMcuProxyConnection(proxy *mcuProxy, baseUrl string, ip net.IP, token str statsProxyBackendLoadCurrent.WithLabelValues(conn.url.String()).Set(0) statsProxyUsageCurrent.WithLabelValues(conn.url.String(), "incoming").Set(0) statsProxyUsageCurrent.WithLabelValues(conn.url.String(), "outgoing").Set(0) + statsProxyBandwidthCurrent.WithLabelValues(conn.url.String(), "incoming").Set(0) + statsProxyBandwidthCurrent.WithLabelValues(conn.url.String(), "outgoing").Set(0) return conn, nil } @@ -754,6 +756,8 @@ func (c *mcuProxyConnection) closeIfEmpty() bool { statsProxyBackendLoadCurrent.DeleteLabelValues(c.url.String()) statsProxyUsageCurrent.DeleteLabelValues(c.url.String(), "incoming") statsProxyUsageCurrent.DeleteLabelValues(c.url.String(), "outgoing") + statsProxyBandwidthCurrent.DeleteLabelValues(c.url.String(), "incoming") + statsProxyBandwidthCurrent.DeleteLabelValues(c.url.String(), "outgoing") c.proxy.removeConnection(c) }() @@ -1090,6 +1094,8 @@ func (c *mcuProxyConnection) processEvent(msg *ProxyServerMessage) { c.bandwidth.Store(event.Bandwidth) statsProxyBackendLoadCurrent.WithLabelValues(c.url.String()).Set(float64(event.Load)) if bw := event.Bandwidth; bw != nil { + statsProxyBandwidthCurrent.WithLabelValues(c.url.String(), "incoming").Set(float64(bw.Received)) + statsProxyBandwidthCurrent.WithLabelValues(c.url.String(), "outgoing").Set(float64(bw.Sent)) if bw.Incoming != nil { statsProxyUsageCurrent.WithLabelValues(c.url.String(), "incoming").Set(*bw.Incoming) } else { diff --git a/mcu_stats_prometheus.go b/mcu_stats_prometheus.go index d1df618..cd063ea 100644 --- a/mcu_stats_prometheus.go +++ b/mcu_stats_prometheus.go @@ -115,6 +115,12 @@ var ( Name: "backend_usage", Help: "The current usage of signaling proxy backends in percent", }, []string{"url", "direction"}) + statsProxyBandwidthCurrent = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "signaling", + Subsystem: "mcu", + Name: "backend_bandwidth", + Help: "The current bandwidth of signaling proxy backends in bytes per second", + }, []string{"url", "direction"}) statsProxyNobackendAvailableTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "signaling", Subsystem: "mcu", @@ -126,6 +132,7 @@ var ( statsConnectedProxyBackendsCurrent, statsProxyBackendLoadCurrent, statsProxyUsageCurrent, + statsProxyBandwidthCurrent, statsProxyNobackendAvailableTotal, } ) diff --git a/proxy/proxy_server.go b/proxy/proxy_server.go index b38b190..93f1f42 100644 --- a/proxy/proxy_server.go +++ b/proxy/proxy_server.go @@ -503,8 +503,12 @@ func (s *ProxyServer) newLoadEvent(load uint64, incoming uint64, outgoing uint64 } maxIncoming := s.maxIncoming.Load() maxOutgoing := s.maxOutgoing.Load() - if maxIncoming > 0 || maxOutgoing > 0 { - msg.Event.Bandwidth = &signaling.EventProxyServerBandwidth{} + if maxIncoming > 0 || maxOutgoing > 0 || incoming != 0 || outgoing != 0 { + // Values should be sent in bytes per second. + msg.Event.Bandwidth = &signaling.EventProxyServerBandwidth{ + Received: incoming / 8, + Sent: outgoing / 8, + } if maxIncoming > 0 { value := float64(incoming) / float64(maxIncoming) * 100 msg.Event.Bandwidth.Incoming = &value