Fix old metrics remaining forever after being removed

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2023-07-30 13:29:02 +01:00
parent cce5533437
commit bfe1115cb5
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
2 changed files with 9 additions and 0 deletions

View File

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

View File

@ -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"