feat: Track the last time we updated the metrics

This commit is contained in:
PapaTutuWawa 2024-01-07 16:42:38 +01:00
parent d4f74661d5
commit 4ceb2023db

14
main.go
View File

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