-
Notifications
You must be signed in to change notification settings - Fork 98
Add MB to used objectstore output #564
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice I think displaying some unit is better than no unit for sure. The only other thing I was thinking was making it a bit dynamic something like a df -h where its relative to the size consumed. I haven't tried this below but the 🤖 vibes was suggesting something like that to get dynamic, without needing an additional dependency. If this is a bad idea, feel free to say its too much. 😃
// humanSize returns a human‑readable string for a value in bytes
// using powers of 1024: B, KB, MB, GB, TB, PB.
func humanSize(bytes int64) string {
const (
_ = iota
KB float64 = 1 << (10 * iota)
MB
GB
TB
PB
)
// use float64 so we can keep two decimal places
value := float64(bytes)
switch {
case value >= PB:
return fmt.Sprintf("%.2f PB", value/PB)
case value >= TB:
return fmt.Sprintf("%.2f TB", value/TB)
case value >= GB:
return fmt.Sprintf("%.2f GB", value/GB)
case value >= MB:
return fmt.Sprintf("%.2f MB", value/MB)
case value >= KB:
return fmt.Sprintf("%.2f KB", value/KB)
default:
return fmt.Sprintf("%d B", bytes)
}
}then update the variable reference if we think this is a good idea
// sizeUsedMB := float64(stats.SizeKBUtilised) / 1024.0
// ow.AppendDataWithLabel("stats", fmt.Sprintf("Objects: %d, Size: %d MB, Size Used: %.2f MB", stats.NumObjects, objectStore.MaxSize, sizeUsedMB), "Stats")
// ---- NEW ----
sizeUsedBytes := int64(stats.SizeKBUtilised) * 1024
humanSizeUsed := humanSize(sizeUsedBytes)
ow.AppendDataWithLabel(
"stats",
fmt.Sprintf("Objects: %d, Size: %d MB, Size Used: %s", stats.NumObjects, objectStore.MaxSize, humanSizeUsed),
"Stats",
)|
Sure thing @NerdyShawn, I agree with the suggestions, I will update the code soon |
|
Sounds good thanks! Also left a comment on the issue but the unit on the 500 is also wrong, that should be a static 500GB I believe. |
b1440a8 to
174c584
Compare
Disambiguating value adding "KB" to the output of civoobjectstore show command #563