獲取磁盤(pán)完整信息
[root@bogon python_auto]# vim disk.py
!/usr/bin/env python
import psutil
disk = psutil.disk_partitions() #利用psutil模塊的disk_partitions()方法
print disk
執(zhí)行查看結(jié)果
[root@bogon python_auto]# python disk.py
[sdiskpart(device='/dev/sda2', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='ext4', opts='rw')]
獲取分區(qū)的使用情況
[root@bogon python_auto]# vim disk.py
!/usr/bin/env python
import psutil
disk = psutil.disk_partitions()
partition = psutil.disk_usage('/')
print partition
執(zhí)行查看結(jié)果
[root@bogon python_auto]# python disk.py
sdiskusage(total=18779398144, used=3674472448, free=14150983680, percent=19.600000000000001)
[root@bogon python_auto]#
獲取磁盤(pán)總的IO個(gè)數(shù)、讀寫(xiě)信息
[root@bogon python_auto]# vim disk.py
!/usr/bin/env python
import psutil
disk = psutil.disk_partitions()
partition = psutil.disk_usage('/')
print partition
io = psutil.disk_io_counters()
print io
執(zhí)行查看結(jié)果
[root@bogon python_auto]# python disk.py
sdiskio(read_count=245556, write_count=118038, read_bytes=5248733184, write_bytes=3704962048, read_time=1424144, write_time=3252612)
[root@bogon python_auto]#
獲取單個(gè)分區(qū)io個(gè)數(shù)券盅、讀寫(xiě)信息。
[root@bogon python_auto]# vim disk.py
!/usr/bin/env python
import psutil
disk = psutil.disk_partitions()
partition = psutil.disk_usage('/')
print partition
io = psutil.disk_io_counters()
print io
perdisk = psutil.disk_io_counters(perdisk=True)
print perdisk
執(zhí)行查看結(jié)果
[root@bogon python_auto]# python disk.py
{'sda2': sdiskio(read_count=243109, write_count=117669, read_bytes=5193733120, write_bytes=3656708096, read_time=1409641, write_time=3249864), 'sda3': sdiskio(read_count=1223, write_count=466, read_bytes=10375168, write_bytes=49188864, read_time=10872, write_time=2831), 'sda1': sdiskio(read_count=1224, write_count=29, read_bytes=44624896, write_bytes=48128, read_time=3631, write_time=83)}
[root@bogon python_auto]#
可以看到磁盤(pán)每個(gè)分區(qū)的詳細(xì)信息都有了。