查看磁盘信息,主要用到了两个方法 psutil.disk_partitions() psutil.disk_usage() 使用方法: 1、安装 psutil pip install psutil 2、进入 python
查看磁盘信息,主要用到了两个方法
使用方法:
1、安装 psutil
pip install psutil
2、进入 python shell,并 import psutil
输入 help(psutil.disk_partitions)
返回
Help on function disk_partitions in module psutil:
disk_partitions(all=False)
Return mounted partitions as a list of
(device, mountpoint, fstype, opts) namedtuple.
'opts' field is a raw string separated by commas indicating mount
options which may vary depending on the platfORM.
If *all* parameter is False return physical devices only and ignore
all others.
输入 help(psutil.disk_usage)
返回
Help on function disk_usage in module psutil:
disk_usage(path)
Return disk usage statistics about the given *path* as a
namedtuple including total, used and free space expressed in bytes
plus the percentage usage.
3、应用
输入 psutil.disk_partitions()
>>> psutil.disk_partitions()
[sdiskpart(device='/dev/disk1', mountpoint='/', fstype='hfs', opts='rw,local,rootfs,dovolfs,journaled,multilabel'), sdiskpart(device='/dev/disk12s2', mountpoint='/Volumes/QQ', fstype='hfs', opts='ro,nosuid,quarantine,local,dovolfs,ignore-ownership,multilabel')]
输入 psutil.disk_usage(‘/’)
>>> psutil.disk_usage("/")
sdiskusage(total=120101666816, used=88392372224, free=31447150592, percent=73.8)
注:上述查到的大小信息单位为 bytes,因此,为了便于直观的观察使用量,应将其转换为M或G为单位的数据
--结束END--
本文标题: Python 查看服务器磁盘信息
本文链接: https://lsjlt.com/news/185392.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0