Raspberry Pi model: Zero W
Raspberry Pi system: Raspbian, 2018-11-13-raspbian-stretch-lite.img
SD card: SanDisk 32G class10 high-speed Micro SD card (TF card)
Python 2.7.3
Use the python-psutil package to query disk information, such as: total space, used space, free space, etc.
Before using it, you need to import psutil. The following is a test program that reads the total space, used space, and free space of the disk and memory, and displays them in GB:
1 # -*- coding:utf-8 -*- 2 import psutil 3 4 def main(): 5 print '>> disk total >> ' + str(psutil.disk_usage("/").total) 6 print '>> disk used >> ' + str(psutil.disk_usage("/").used) 7 print '>> disk avail >> ' + str(psutil.disk_usage("/").free) 8 print '>> disk percent >> ' + str(psutil.disk_usage("/").percent) + ' %' + '\n' 9 10 print '>> disk total/G >> ' + \ 11 str(round((((float(psutil.disk_usage("/").total)/1024)/1024)/1024), 2)) + 'G' 12 print '>> disk used /G >> ' + \ 13 str(round((((float(psutil.disk_usage("/").used) /1024)/1024)/1024), 2)) + 'G' 14 print '>> disk avail/G >> ' + \ 15 str(round((((float(psutil.disk_usage("/").free) /1024)/1024)/1024), 2)) + 'G' + '\n' 16 17 virtual_mem = psutil.virtual_memory() 18 print '>> mem total >> ' + str(virtual_mem.total) 19 print '>> mem used >> ' + str(virtual_mem.total - virtual_mem.available) 20 print '>> mem avail >> ' + str(virtual_mem.available) + '\n' 21 22 print '>> mem total /G >> ' + \ 23 str(round((((float(virtual_mem.total)/1024)/1024)/1024), 2)) + 'G' 24 print '>> mem used /G >> ' + \ 25 str(round((((float(virtual_mem.total-virtual_mem.available)/1024)/1024)/1024),2))+'G' 26 print '>> mem avail /G >> ' + \ 27 str(round((((float(virtual_mem.available)/1024)/1024)/1024), 2)) + 'G' + '\n' 28 29 if __name__ == ' hand ()30': __main__
Show results
Extended Information
Psutil official documentation https://psutil.readthedocs.io/en/latest/
Mainly provide the following types of functions:
System
- CPU
- Memory
- Disks
- Network
- Sensors
- Other system info
Processes
Windows services
For detailed information and usage, you can directly look at the official documentation, which is very detailed.