Skip to content

Conversation

@fulviodenza
Copy link
Contributor

Disambiguating value adding "KB" to the output of civoobjectstore show command #563

@fulviodenza fulviodenza changed the title Add KB to used objectstore output Add MB to used objectstore output Oct 17, 2025
Copy link

@NerdyShawn NerdyShawn left a 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",
)

@fulviodenza
Copy link
Contributor Author

Sure thing @NerdyShawn, I agree with the suggestions, I will update the code soon

@NerdyShawn
Copy link

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.

@fulviodenza fulviodenza force-pushed the 563-object-store-used-stats branch from b1440a8 to 174c584 Compare November 26, 2025 13:54
@giornetta giornetta merged commit b1af0d7 into master Nov 26, 2025
3 checks passed
@giornetta giornetta mentioned this pull request Nov 26, 2025
@fulviodenza fulviodenza deleted the 563-object-store-used-stats branch November 26, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants