giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.38k forks source link

psutil.disk_usage() sometimes not works on Ubuntu Linux #935

Closed DingGuodong closed 7 years ago

DingGuodong commented 7 years ago

Today I use this statement in python 2.7, but get a wrong data on Ubuntu 14.04.1 Linux system. I think this maybe a issue.

print psutil.disk_usage('/dev/sda1')

next, I will use text to replace the image.

root@file-storage-1:~/deploy_to_test/projects/others/testOps/tmp# python getDiskUsage.py 
/dev/sda1 / sdiskusage(total=8402960384, used=4096, free=8402956288, percent=0.0)
sdiskusage(total=8402960384, used=4096, free=8402956288, percent=0.0)
root@file-storage-1:~/deploy_to_test/projects/others/testOps/tmp# df /dev/sda1 | tail -n1
/dev/sda1      447809368 185856228 239182708   44% /
root@file-storage-1:~/deploy_to_test/projects/others/testOps/tmp# uname -a
Linux file-storage-1 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
root@file-storage-1:~/deploy_to_test/projects/others/testOps/tmp# cat /proc/version
Linux version 3.19.0-25-generic (buildd@lgw01-20) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015
root@file-storage-1:~/deploy_to_test/projects/others/testOps/tmp#

Thanks and best regards!

DingGuodong commented 7 years ago

Sorry my abuse, I should use 'psutil.disk_usage(partition.mountpoint)' to get disk usage. sorry about that. Now I know 'psutil.disk_usage('/dev/sda1')' is calculating '/dev' usage in fact. Please close this 'issue'.