Skip to content

Commit

Permalink
Merge pull request #3 from Cyb3r-Jak3/remove-total-storage-metric
Browse files Browse the repository at this point in the history
Remove total storage metric
  • Loading branch information
Cyb3r-Jak3 committed Aug 4, 2024
2 parents 864fed4 + e8057e8 commit 7da0647
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ jobs:
with:
go-version-file: go.mod

- name: Install syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
syft version
- name: GoReleaser Action
uses: goreleaser/goreleaser-action@v6
with:
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
GIT_VERSION ?= $(shell git describe --tags --always --dirty="-dev")
DATE ?= $(shell date -u '+%Y-%m-%d %H:%M UTC')
VERSION_FLAGS := -s -w -X "main.version=$(GIT_VERSION)" -X "main.date=$(DATE)"
CGO_ENABLED ?= 0
.PHONY: build
build:
CGO_ENABLED=0 go build --ldflags '-w -s -extldflags "-static"' -o cloudflare_exporter .
go build -trimpath --ldflags '$(VERSION_FLAGS) -extldflags "-static"' -o cloudflare_exporter .
lint:
golangci-lint run
clean:
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,24 @@ Note: `ZONE_<name>` configuration is not supported as flag.
# HELP cloudflare_logpush_failed_jobs_zone_count Number of failed logpush jobs on the zone level
# 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
```

## Helm chart repository
To deploy the exporter into Kubernetes, we recommend using our manager Helm repository:
[//]: # (## Helm chart repository)

```
helm repo add cloudflare-exporter https://lablabs.github.io/cloudflare-exporter/
helm install cloudflare-exporter/cloudflare-exporter
```
[//]: # (To deploy the exporter into Kubernetes, we recommend using our manager Helm repository:)

[//]: # ()
[//]: # (```)

[//]: # (helm repo add cloudflare-exporter https://lablabs.github.io/cloudflare-exporter/)

[//]: # (helm install cloudflare-exporter/cloudflare-exporter)

[//]: # (```)

## Docker
### Build
Images are available at [Github Container Registry](https://github.com/lablabs/cloudflare-exporter/pkgs/container/cloudflare_exporter)
Images are available at [Github Container Registry](https://github.com/Cyb3r-Jak3/cloudflare-exporter/pkgs/container/cloudflare_exporter)

```
docker build -t ghcr.io/Cyb3r-Jak3/cloudflare_exporter .
Expand Down Expand Up @@ -150,7 +154,7 @@ docker run --rm -p 8080:8080 -e CF_API_TOKEN=${CF_API_TOKEN} -e FREE_TIER=true g

Access help:
```
docker run --rm -p 8080:8080 -i ghcr.io/lablabs/cloudflare_exporter --help
docker run --rm -p 8080:8080 -i ghcr.io/Cyb3r-Jak3/cloudflare_exporter --help
```

## Contributing and reporting issues
Expand Down
1 change: 0 additions & 1 deletion cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ func fetchR2Account(accountID string) (*cloudflareResponseR2Account, error) {

ctx := context.Background()
graphqlClient := graphql.NewClient(cfGraphQLEndpoint)
graphqlClient.Log = func(s string) { log.Debug(s) }
var resp cloudflareResponseR2Account
if err := graphqlClient.Run(ctx, request, &resp); err != nil {
log.Errorf("Error fetching R2 account: %s", err)
Expand Down
13 changes: 0 additions & 13 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const (
poolRequestsTotalMetricName MetricName = "cloudflare_zone_pool_requests_total"
logpushFailedJobsAccountMetricName MetricName = "cloudflare_logpush_failed_jobs_account_count"
logpushFailedJobsZoneMetricName MetricName = "cloudflare_logpush_failed_jobs_zone_count"
r2StorageTotalMetricName MetricName = "cloudflare_r2_storage_total_bytes"
r2StorageMetricName MetricName = "cloudflare_r2_storage_bytes"
r2OperationMetricName MetricName = "cloudflare_r2_operation_count"
)
Expand Down Expand Up @@ -271,11 +270,6 @@ var (
[]string{"destination", "job_id", "final"},
)

r2StorageTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: r2StorageTotalMetricName.String(),
Help: "Total storage used by R2",
}, []string{"account"})

r2Storage = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: r2StorageMetricName.String(),
Help: "Storage used by R2",
Expand Down Expand Up @@ -321,7 +315,6 @@ func buildAllMetricsSet() MetricsSet {
allMetricsSet.Add(poolRequestsTotalMetricName)
allMetricsSet.Add(logpushFailedJobsAccountMetricName)
allMetricsSet.Add(logpushFailedJobsZoneMetricName)
allMetricsSet.Add(r2StorageTotalMetricName)
allMetricsSet.Add(r2OperationMetricName)
allMetricsSet.Add(r2StorageMetricName)
return allMetricsSet
Expand Down Expand Up @@ -437,9 +430,6 @@ func mustRegisterMetrics(deniedMetrics MetricsSet) {
if !deniedMetrics.Has(logpushFailedJobsZoneMetricName) {
prometheus.MustRegister(logpushFailedJobsZone)
}
if !deniedMetrics.Has(r2StorageTotalMetricName) {
prometheus.MustRegister(r2StorageTotal)
}
if !deniedMetrics.Has(r2StorageMetricName) {
prometheus.MustRegister(r2Storage)
}
Expand Down Expand Up @@ -517,15 +507,12 @@ func fetchR2StorageForAccount(account cloudflare.Account, wg *sync.WaitGroup) {
return
}
for _, acc := range r.Viewer.Accounts {
var totalStorage uint64
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))
}
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))
}
r2StorageTotal.With(prometheus.Labels{"account": account.Name}).Set(float64(totalStorage))
}
}

Expand Down

0 comments on commit 7da0647

Please sign in to comment.