From 573f3336a42a9899f5075dbd57dfb76a57e0e0b5 Mon Sep 17 00:00:00 2001 From: Tomasz Kolodziej Date: Mon, 30 Jul 2018 14:59:23 +0200 Subject: [PATCH] Fixing calculation of UsedPercent. Now it is calculated based of available disk space for user, not including reserved space for root. This is compatible with psutil and df command. --- disk/disk_unix.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/disk/disk_unix.go b/disk/disk_unix.go index c947848..51bd6f3 100644 --- a/disk/disk_unix.go +++ b/disk/disk_unix.go @@ -47,10 +47,11 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 } - if ret.Total == 0 { + if (ret.Used + ret.Free) == 0 { ret.UsedPercent = 0 } else { - ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + + ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0 } return ret, nil