From 12bd4115e30be6ffb2a65b11c80fee0e78558724 Mon Sep 17 00:00:00 2001 From: Gouryella Date: Mon, 5 Jan 2026 13:38:08 +0800 Subject: [PATCH] feat(tunnel/manager): update tunnel IP metrics statistics - Synchronously delete corresponding Prometheus metrics when removing IP records - Update metric values when the number of IP tunnels changes - Ensure accuracy and real-time nature of the tunnelsByIP metric --- internal/server/tunnel/manager.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/server/tunnel/manager.go b/internal/server/tunnel/manager.go index 2227110..7a964fb 100644 --- a/internal/server/tunnel/manager.go +++ b/internal/server/tunnel/manager.go @@ -233,6 +233,9 @@ func (m *Manager) RegisterWithIP(conn *websocket.Conn, customSubdomain string, r m.tunnelsByIP[remoteIP]-- if m.tunnelsByIP[remoteIP] == 0 { delete(m.tunnelsByIP, remoteIP) + metrics.TunnelsByIP.DeleteLabelValues(remoteIP) + } else { + metrics.TunnelsByIP.WithLabelValues(remoteIP).Set(float64(m.tunnelsByIP[remoteIP])) } } m.ipMu.Unlock() @@ -410,6 +413,9 @@ func (m *Manager) CleanupStale(timeout time.Duration) int { m.tunnelsByIP[remoteIP]-- if m.tunnelsByIP[remoteIP] == 0 { delete(m.tunnelsByIP, remoteIP) + metrics.TunnelsByIP.DeleteLabelValues(remoteIP) + } else { + metrics.TunnelsByIP.WithLabelValues(remoteIP).Set(float64(m.tunnelsByIP[remoteIP])) } } m.ipMu.Unlock()