From f1aa0814dcb1fe70a558ac29ecaea0a8b039251c Mon Sep 17 00:00:00 2001 From: whywaita Date: Tue, 10 Dec 2024 17:50:37 +0900 Subject: [PATCH] Add target_token_expires_seconds --- pkg/metric/scrape_datastore.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/metric/scrape_datastore.go b/pkg/metric/scrape_datastore.go index a668867..2b0603b 100644 --- a/pkg/metric/scrape_datastore.go +++ b/pkg/metric/scrape_datastore.go @@ -37,6 +37,11 @@ var ( "resource_type", }, nil, ) + datastoreTargetTokenExpiresDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, datastoreName, "target_token_expires_seconds"), + "Token expires time", + []string{"target_id"}, nil, + ) datastoreJobDurationOldest = prometheus.NewDesc( prometheus.BuildFQName(namespace, datastoreName, "job_duration_oldest_seconds"), "Duration time of oldest job", @@ -179,6 +184,7 @@ func scrapeTargets(ctx context.Context, ds datastore.Datastore, ch chan<- promet return fmt.Errorf("failed to list targets: %w", err) } + now := time.Now() result := map[string]float64{} // key: resource_type, value: number for _, t := range targets { ch <- prometheus.MustNewConstMetric( @@ -187,6 +193,12 @@ func scrapeTargets(ctx context.Context, ds datastore.Datastore, ch chan<- promet ) result[t.ResourceType.String()]++ + + ch <- prometheus.MustNewConstMetric( + datastoreTargetTokenExpiresDesc, prometheus.GaugeValue, + t.TokenExpiredAt.Sub(now).Seconds(), + t.UUID.String(), + ) } for rt, number := range result { ch <- prometheus.MustNewConstMetric(