Fix initial lifetime update

This commit is contained in:
Torjus Håkestad 2025-06-03 22:52:55 +02:00
parent 4b7ab8cd0f
commit 040a73e891
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
3 changed files with 7 additions and 3 deletions

View File

@ -17,7 +17,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
const Version = "0.1.1" const Version = "0.1.2"
func LoadConfig() (*config.Config, error) { func LoadConfig() (*config.Config, error) {
path := "labmon.toml" path := "labmon.toml"

View File

@ -68,6 +68,8 @@ func (sm *StepMonitor) Start() {
stepCertError.WithLabelValues(sm.RootID).Set(1) stepCertError.WithLabelValues(sm.RootID).Set(1)
} else { } else {
stepCertError.WithLabelValues(sm.RootID).Set(0) 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() secondsLeft := time.Until(sm.certificate.NotAfter).Seconds()
stepCertTimeLeft.WithLabelValues(sm.RootID).Set(secondsLeft) stepCertTimeLeft.WithLabelValues(sm.RootID).Set(secondsLeft)

View File

@ -111,12 +111,12 @@ func (tm *TLSConnectionMonitor) Start(ctx context.Context) {
if err := tm.fetchCert(ctx); err != nil { if err := tm.fetchCert(ctx); err != nil {
gaugeCertError.WithLabelValues(tm.Address).Set(1) gaugeCertError.WithLabelValues(tm.Address).Set(1)
gaugeCertTimeLeft.WithLabelValues(tm.Address).Set(0) gaugeCertTimeLeft.WithLabelValues(tm.Address).Set(0)
lifetime := tm.cert.NotAfter.Sub(tm.cert.NotBefore).Seconds()
gaugeCertLifetime.WithLabelValues(tm.Address).Set(lifetime)
} else { } else {
gaugeCertError.WithLabelValues(tm.Address).Set(0) gaugeCertError.WithLabelValues(tm.Address).Set(0)
timeLeft := time.Until(tm.cert.NotAfter).Seconds() timeLeft := time.Until(tm.cert.NotAfter).Seconds()
gaugeCertTimeLeft.WithLabelValues(tm.Address).Set(timeLeft) 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) timerCertFetch := time.NewTimer(tm.CheckDuration)
@ -131,6 +131,8 @@ func (tm *TLSConnectionMonitor) Start(ctx context.Context) {
gaugeCertError.WithLabelValues(tm.Address).Set(1) gaugeCertError.WithLabelValues(tm.Address).Set(1)
} else { } else {
gaugeCertError.WithLabelValues(tm.Address).Set(0) 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) timerCertFetch.Reset(tm.CheckDuration)
case <-timerUpdateMonitor.C: case <-timerUpdateMonitor.C: