gopsutil
gopsutil copied to clipboard
[disk] Modify stat free, from bavail to bfree
From:
Free: (uint64(stat.Bavail) * uint64(bsize)),
To:
Free: (uint64(stat.Bfree) * uint64(bsize)),
https://pkg.go.dev/golang.org/x/sys/unix#Statfs_t
type Statfs_t
type Statfs_t struct {
Type int64
Bsize int64
Blocks uint64
Bfree uint64 /* free blocks in fs */
Bavail uint64 /* free blocks avail to non-superuser */
Files uint64
Ffree uint64
Fsid Fsid
Namelen int64
Frsize int64
Flags int64
Spare [4]int64
}
In some cases, the old implementation may have Total-Free!=Used。
According to the psutil implementation, Free is a "avail_to_user", not a "avail_to_root". Could you tell us what Linux kernel version think Total-Free! = Used?
According to the psutil implementation,
Freeis a "avail_to_user", not a "avail_to_root". Could you tell us what Linux kernel version thinkTotal-Free! = Used?
Thanks for your replay!
I encountered this problem in ‘CentOS Linux release 7.7.1908 (Core)’.
I think Total-Free! = Used may be caused by the following reasons :total is only available to root, free is avail_to_user, not avail_to_root, used is (total-avail_to_root), so total - free != uesd。
But I don't know if it is intentional to do so.
Because the github.com/giampaolo/psutil readme example is also Total-Free! = Used.
According to the psutil implementation line 190, psutil implementation line 194, Free is a "avail_to_root", not a "avail_to_user". the purpose of "avail_to_user" is to calculate "usage_percent_user".