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(