From 4ceb2023dbcfa71d7fd0d4bae975ade4fbe0edf8 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 7 Jan 2024 16:42:38 +0100 Subject: [PATCH] feat: Track the last time we updated the metrics --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 178a68a..3cbfa6b 100644 --- a/main.go +++ b/main.go @@ -88,8 +88,9 @@ func (c *CertificateMetrics) checkTls() { } } -func updateMetrics(metrics *[]CertificateMetrics) { +func updateMetrics(metrics *[]CertificateMetrics, lastUpdated prometheus.Gauge) { log.Debugf("Updating metrics for %d domains...", len(*metrics)) + lastUpdated.SetToCurrentTime() for _, metric := range *metrics { metric.checkTls() } @@ -108,6 +109,13 @@ func run(ctx *cli.Context) error { // Setup metrics registry := prometheus.NewRegistry() + lastUpdatedMetric := prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "certs_status_last_updated", + }, + ) + registry.MustRegister(lastUpdatedMetric) + metrics := make([]CertificateMetrics, 0) for _, d := range domains { log.Debugf("Parsing '%s'...", d) @@ -155,7 +163,7 @@ func run(ctx *cli.Context) error { gocron.DurationJob(24*time.Hour), gocron.NewTask( func() { - updateMetrics(&metrics) + updateMetrics(&metrics, lastUpdatedMetric) }, ), ) @@ -166,7 +174,7 @@ func run(ctx *cli.Context) error { // Perform an initial run to populate the metrics log.Info("Performing initial requests...") - updateMetrics(&metrics) + updateMetrics(&metrics, lastUpdatedMetric) log.Debug("Done") http.Handle(