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
This commit is contained in:
Gouryella
2026-01-05 13:38:08 +08:00
parent d03874b3d3
commit 12bd4115e3

View File

@@ -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()