Skip to content

Commit

Permalink
add r2_object_count
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Sep 25, 2024
1 parent 26f0536 commit dfecde3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Note: `ZONE_<name>` configuration is not supported as flag.
# HELP cloudflare_r2_operation_count Number of operations performed by R2
# HELP cloudflare_r2_storage_bytes Storage used by R2
# HELP cloudflare_r2_storage_total_bytes Total storage used by R2
# HELP cloudflare_r2_object_count Number of objects in bucket
```

## Helm chart repository
Expand Down
10 changes: 10 additions & 0 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
r2StorageTotalMetricName MetricName = "cloudflare_r2_storage_total_bytes"
r2StorageMetricName MetricName = "cloudflare_r2_storage_bytes"
r2OperationMetricName MetricName = "cloudflare_r2_operation_count"
r2ObjectCountMetricName MetricName = "cloudflare_r2_object_count"
)

type MetricsSet map[MetricName]struct{}
Expand Down Expand Up @@ -280,6 +281,10 @@ var (
Name: r2OperationMetricName.String(),
Help: "Number of operations performed by R2",
}, []string{"account", "bucket", "operation"})
r2ObjectCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: r2ObjectCountMetricName.String(),
Help: "Number of objects in bucket",
}, []string{"account", "bucket"})
)

func buildAllMetricsSet() MetricsSet {
Expand Down Expand Up @@ -318,6 +323,7 @@ func buildAllMetricsSet() MetricsSet {
allMetricsSet.Add(logpushFailedJobsZoneMetricName)
allMetricsSet.Add(r2StorageTotalMetricName)
allMetricsSet.Add(r2OperationMetricName)
allMetricsSet.Add(r2ObjectCountMetricName)
return allMetricsSet
}

Expand Down Expand Up @@ -440,6 +446,9 @@ func mustRegisterMetrics(deniedMetrics MetricsSet) {
if !deniedMetrics.Has(r2OperationMetricName) {
prometheus.MustRegister(r2Operation)
}
if !deniedMetrics.Has(r2ObjectCountMetricName) {
prometheus.MustRegister(r2ObjectCount)
}

}

Expand Down Expand Up @@ -509,6 +518,7 @@ func fetchR2StorageForAccount(account cloudflare.Account, wg *sync.WaitGroup) {
for _, bucket := range acc.R2StorageGroups {
totalStorage += bucket.Max.PayloadSize
r2Storage.With(prometheus.Labels{"account": account.Name, "bucket": bucket.Dimensions.BucketName}).Set(float64(bucket.Max.PayloadSize))
r2ObjectCount.With(prometheus.Labels{"account": account.Name, "bucket": bucket.Dimensions.BucketName}).Set(float64(bucket.Max.ObjectCount))
}
for _, operation := range acc.R2StorageOperations {
r2Operation.With(prometheus.Labels{"account": account.Name, "bucket": operation.Dimensions.BucketName, "operation": operation.Dimensions.Action}).Set(float64(operation.Sum.Requests))
Expand Down

0 comments on commit dfecde3

Please sign in to comment.