Skip to content

Commit

Permalink
Add target_token_expires_seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Dec 10, 2024
1 parent 83a541b commit f1aa081
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/metric/scrape_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit f1aa081

Please sign in to comment.