I am writing a simple monitoring script to which I would like to add disk space checks. I found however that the reported free space is different between the system df
and shutils.disk_usage()
.
On a system which has three disks mounted:
# df / /mnt/2TB1 /mnt/1TB1
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 472437724 231418380 216997128 52% /
/dev/sdb1 1921802520 1712163440 111947020 94% /mnt/2TB1
/dev/sdc1 960380648 347087300 564438888 39% /mnt/1TB1
# python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> (t, u, f) = shutil.disk_usage('/')
>>> (t, u, f)
(483776229376, 236973805568, 222203674624)
>>> u/t
0.48984177224594366
>>> (t, u, f) = shutil.disk_usage('/mnt/2TB1')
>>> (t, u, f)
(1967925780480, 1753255362560, 114633748480)
>>> u/t
0.8909153891628782
>>> (t, u, f) = shutil.disk_usage('/mnt/1TB1')
>>> (t, u, f)
(983429783552, 355400192000, 578002624512)
>>> u/t
0.361388477290517
The difference is respectively 3%, 5% and 3%. Where does it come from and which result is the correct one?