From 040a73e891a70ff06ec7ab31d7167914129dbf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 3 Jun 2025 22:52:55 +0200 Subject: [PATCH] Fix initial lifetime update --- main.go | 2 +- stepmon/stepmon.go | 2 ++ tlsconmon/tlsconmon.go | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 04ae0cc..43626f4 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -const Version = "0.1.1" +const Version = "0.1.2" func LoadConfig() (*config.Config, error) { path := "labmon.toml" diff --git a/stepmon/stepmon.go b/stepmon/stepmon.go index 3250cf9..77bd0d4 100644 --- a/stepmon/stepmon.go +++ b/stepmon/stepmon.go @@ -68,6 +68,8 @@ func (sm *StepMonitor) Start() { stepCertError.WithLabelValues(sm.RootID).Set(1) } else { stepCertError.WithLabelValues(sm.RootID).Set(0) + lifetime := sm.certificate.NotAfter.Sub(sm.certificate.NotBefore).Seconds() + stepCertLifetime.WithLabelValues(sm.RootID).Set(lifetime) } secondsLeft := time.Until(sm.certificate.NotAfter).Seconds() stepCertTimeLeft.WithLabelValues(sm.RootID).Set(secondsLeft) diff --git a/tlsconmon/tlsconmon.go b/tlsconmon/tlsconmon.go index a1d1602..f92c6c5 100644 --- a/tlsconmon/tlsconmon.go +++ b/tlsconmon/tlsconmon.go @@ -111,12 +111,12 @@ func (tm *TLSConnectionMonitor) Start(ctx context.Context) { if err := tm.fetchCert(ctx); err != nil { gaugeCertError.WithLabelValues(tm.Address).Set(1) gaugeCertTimeLeft.WithLabelValues(tm.Address).Set(0) - lifetime := tm.cert.NotAfter.Sub(tm.cert.NotBefore).Seconds() - gaugeCertLifetime.WithLabelValues(tm.Address).Set(lifetime) } else { gaugeCertError.WithLabelValues(tm.Address).Set(0) timeLeft := time.Until(tm.cert.NotAfter).Seconds() gaugeCertTimeLeft.WithLabelValues(tm.Address).Set(timeLeft) + lifetime := tm.cert.NotAfter.Sub(tm.cert.NotBefore).Seconds() + gaugeCertLifetime.WithLabelValues(tm.Address).Set(lifetime) } timerCertFetch := time.NewTimer(tm.CheckDuration) @@ -131,6 +131,8 @@ func (tm *TLSConnectionMonitor) Start(ctx context.Context) { gaugeCertError.WithLabelValues(tm.Address).Set(1) } else { gaugeCertError.WithLabelValues(tm.Address).Set(0) + lifetime := tm.cert.NotAfter.Sub(tm.cert.NotBefore).Seconds() + gaugeCertLifetime.WithLabelValues(tm.Address).Set(lifetime) } timerCertFetch.Reset(tm.CheckDuration) case <-timerUpdateMonitor.C: