Skip to content

Commit

Permalink
feat: expose timestamp for when current metrics are from
Browse files Browse the repository at this point in the history
Since metrics are not live, but an arbitrary date in the past few days
depending on when reports are available to, it seems like a reasonable
idea to include the timestamp of the date that the current data is from.
  • Loading branch information
jimeh committed Oct 29, 2023
1 parent 89ddadc commit 9fd2706
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ import (
var statsTemplate string

type QuotaCollector struct {
total *prometheus.Desc
used *prometheus.Desc
client *admin.Service
timestamp *prometheus.Desc
total *prometheus.Desc
used *prometheus.Desc
client *admin.Service
}

func NewQuotaCollector(client *admin.Service) *QuotaCollector {
return &QuotaCollector{
timestamp: prometheus.NewDesc("google_workspace_quota_timestamp",
"Timestamp of the quota stats",
nil, nil,
),
total: prometheus.NewDesc("google_workspace_quota_bytes_total",
"Total quota in bytes",
nil, nil,
Expand All @@ -51,7 +56,7 @@ func (c *QuotaCollector) Describe(ch chan<- *prometheus.Desc) {
}

func (c *QuotaCollector) Collect(ch chan<- prometheus.Metric) {
_, totalQuota, usedQuota, _, err := c.fetchQuotaStats()
t, totalQuota, usedQuota, _, err := c.fetchQuotaStats()
if err != nil {
slog.Error(
"Failed to fetch quota stats",
Expand All @@ -60,6 +65,9 @@ func (c *QuotaCollector) Collect(ch chan<- prometheus.Metric) {
return
}

ch <- prometheus.MustNewConstMetric(
c.timestamp, prometheus.GaugeValue, float64(t.Unix()),
)
ch <- prometheus.MustNewConstMetric(
c.total, prometheus.GaugeValue, totalQuota*1048576,
)
Expand Down

0 comments on commit 9fd2706

Please sign in to comment.