Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use manually given cluster capacity value if given #74

Merged
merged 4 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Additionally, the following environment variables are recognized:
| ---------------- | ---------------- | ---------------- |
| `SWIFT_DISPERSION_REPORT_PATH` | yes, if executable not in `$PATH` and `dispersion` collector is enabled | Path to the `swift-dispersion-report` executable. |
| `SWIFT_RECON_PATH` | yes, if executable not in `$PATH` and any `recon.<name>` collector is enabled | Path to the `swift-recon` executable. |
| `SWIFT_CLUSTER_RAW_CAPACITY_BYTES` | no | This cluster capacity value (in bytes) will be used for `swift_cluster_storage_capacity_bytes` metric instead of calculating total capacity using `swift-recon` tool. |
| `DEBUG` | no | If this option is set to `true` then `swift-health-exporter` will also output debug logs. |

## Collectors
Expand Down
17 changes: 16 additions & 1 deletion internal/collector/recon/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package recon
import (
"encoding/json"
"fmt"
"os"
"regexp"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/sapcc/go-bits/logg"
Expand Down Expand Up @@ -156,8 +158,21 @@ func (t *DiskUsageTask) UpdateMetrics() (map[string]int, error) {
}
}

if rawCapStr := os.Getenv("SWIFT_CLUSTER_RAW_CAPACITY_BYTES"); rawCapStr != "" {
rawCap, err := strconv.ParseFloat(rawCapStr, 64)
if err != nil {
logg.Error("could not parse 'SWIFT_CLUSTER_RAW_CAPACITY_BYTES' value: %s", err.Error())
} else {
totalSize = flexibleFloat64(rawCap)
}
}

usageRatio := float64(totalUsed) / float64(totalSize)
if totalSize == 0 {
// The usageRatio value can be greater than 1:
// 1. if the manually given total capacity (SWIFT_CLUSTER_RAW_CAPACITY_BYTES) is less than
// the total capacity reported by 'swift-recon' tool
// 2. and the usage is greater than the manually given total capacity.
if totalSize == 0 || usageRatio > 1 {
usageRatio = 1.0
}

Expand Down