Fix for diskusage Ceph mount

This sets `used` and `usedPercent` correctly in #1344
pull/1345/head
Ties de Wit 3 years ago committed by GitHub
parent ed37dc27a2
commit 43d805cf5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,13 +27,22 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
InodesFree: (uint64(stat.Ffree)),
}
ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize)
if (ret.Used + ret.Free) == 0 {
ret.UsedPercent = 0
} else {
// We don't use ret.Total to calculate percent.
// see https://github.com/shirou/gopsutil/issues/562
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}
// if could not get InodesTotal, return empty
if ret.InodesTotal < ret.InodesFree {
return ret, nil
}
ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize)
if ret.InodesTotal == 0 {
ret.InodesUsedPercent = 0
@ -41,14 +50,6 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0
}
if (ret.Used + ret.Free) == 0 {
ret.UsedPercent = 0
} else {
// We don't use ret.Total to calculate percent.
// see https://github.com/shirou/gopsutil/issues/562
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}
return ret, nil
}

Loading…
Cancel
Save