Fix initial lifetime update

This commit is contained in:
2025-06-03 22:52:55 +02:00
parent 4b7ab8cd0f
commit 040a73e891
3 changed files with 7 additions and 3 deletions

View File

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