diff --git a/pkg/metrics/devices.go b/pkg/metrics/devices.go index 3bdf351..2b10816 100644 --- a/pkg/metrics/devices.go +++ b/pkg/metrics/devices.go @@ -48,6 +48,11 @@ func collectDevices(client *tailscale.Client) []prometheus.Collector { if err != nil { fmt.Println("Failed to get devices: ", err) } else { + // Reset gauges so we don't leave old devices around + deviceExpiry.Reset() + deviceSecondsRemaining.Reset() + deviceUpdateAvailable.Reset() + for _, device := range devices { if !device.KeyExpiryDisabled { remainingSeconds := time.Until(device.Expires.Time).Seconds() diff --git a/pkg/metrics/keys.go b/pkg/metrics/keys.go index cd587a5..a0ad8bd 100644 --- a/pkg/metrics/keys.go +++ b/pkg/metrics/keys.go @@ -37,6 +37,10 @@ func collectKeys(client *tailscale.Client) []prometheus.Collector { if err != nil { fmt.Println("Failed to get keys: ", err) } else { + // Reset gauges so we don't leave old keys around + keyExpiry.Reset() + keySecondsRemaining.Reset() + for _, key := range keys { remainingSeconds := time.Until(key.Expires).Seconds() keyType := "auth_key"