You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
828 B

package systemmetrics
import (
"errors"
"math"
"tera-clone/services/tera-api/internal/domain"
)
// Free blocks include the filesystem reservation; available blocks do not.
// The meter reports physical usage, while available bytes reflect writable space.
func storageMetrics(path string, blocks, free, available, blockSize uint64) (*domain.StorageMetrics, error) {
if blocks == 0 || blockSize == 0 || free > blocks || available > free || blocks > math.MaxUint64/blockSize {
return nil, errors.New("invalid storage metrics")
}
return &domain.StorageMetrics{
Path: path, TotalBytes: blocks * blockSize, UsedBytes: (blocks - free) * blockSize,
AvailableBytes: available * blockSize, ReservedBytes: (free - available) * blockSize,
UsagePercent: math.Round(float64(blocks-free)/float64(blocks)*1000) / 10,
}, nil
}