python psutil.disk_Python psutil.disk_partitions方法代碼示例

本文详细介绍了Python的psutil库中disk_partitions方法的多个使用示例,包括获取系统磁盘分区信息并计算使用情况。通过示例展示了如何遍历分区,获取挂载点、文件系统类型、使用率等信息,适用于系统监控、资源管理等场景。
摘要由CSDN通过智能技术生成

本文整理匯總了Python中psutil.disk_partitions方法的典型用法代碼示例。如果您正苦於以下問題:Python psutil.disk_partitions方法的具體用法?Python psutil.disk_partitions怎麽用?Python psutil.disk_partitions使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊psutil的用法示例。

在下文中一共展示了psutil.disk_partitions方法的28個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: __init__

​點讚 6

# 需要導入模塊: import psutil [as 別名]

# 或者: from psutil import disk_partitions [as 別名]

def __init__(self):

self.timestamp = time.time()

self.cpu_load = []

self.mem = dict(total = 0,

available = 0,

free = 0,

cached = 0,

buffers = 0)

self.disk_partitions = {}

self.network = {}

partitions = psutil.disk_partitions()

for p in partitions:

if p.mountpoint in self.INCLUDED_PARTITIONS:

usage = psutil.disk_usage(p.mountpoint)

self.disk_partitions[p.mountpoint] = {

'total': usage.total,

'used': usage.used

}

開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:21,

示例2: getStatus

​點讚 6

# 需要導入模塊: import psutil [as 別名]

# 或者: from psutil import disk_partitions [as 別名]

def getStatus(self, max_age=0.8):

"""

Get current system status.

max_age: maximum tolerable age of cached status information. Set to

None to force a refresh regardless of cache age.

Returns a dictionary with fields 'cpu_load', 'mem', 'disk', and

'network'.

"""

timestamp = time.time()

if (max_age is None or timestamp > self.timestamp + max_age):

self.timestamp = timestamp

self.refreshCpuLoad()

self.refreshMemoryInfo()

self.refreshDiskInfo()

self.refreshNetworkTraffic()

result = {

'cpu_load': self.cpu_load,

'mem': self.mem,

'disk': self.disk_partitions,

'network': self.network

}

return result

開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:27,

示例3: getSystemInfo

​點讚 6

# 需要導入模塊: import psutil [as 別名]

# 或者: from psutil import disk_partitions [as 別名]

def getSystemInfo(cls):

system = {

'boot_time': psutil.boot_time(),

'cpu_count': psutil.cpu_count(),

'cpu_stats': psutil.cpu_stats().__dict__,

'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],

'disk_io_counters': psutil.disk_io_counters().__dict__,

'disk_usage': [],

'net_io_counters': psutil.net_io_counters().__dict__,

'swap_memory': psutil.swap_memory().__dict__,

'virtual_memory': psutil.virtual_memory().__dict__

}

partitions = psutil.disk_partitions()

for p in partitions:

if p.mountpoint in cls.INCLUDED_PARTITIONS:

usage = psutil.disk_usage(p.mountpoint)

system['disk_usage'].append({

'mountpoint': p.mountpoint,

'total': usage.total,

'used': usage.used

})

return system

開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:26,

示例4: getMountPath

​點讚 6

# 需要導入模塊: import psutil [as 別名]

# 或者: from psutil import disk_partitions [as 別名]

def getMountPath(device):

"""

Checks if the partition is mounted if not it return ""

:param device: Target device being string "OP1" or "OPZ"

:return: "" is not found

"""

mountpath = getmountpath(device)

# mountPoint = ""

for i, disk in enumerate(disk_partitions()):

print(disk)

if disk.device == mountpath:

mountPoint = disk.mountpoint

if device == "OP1":

config["OP_1_Mounted_Dir"] = mountPoint

print(config["OP_1_Mounted_Dir"])

elif device == "OPZ":

config["OP_Z_Mounted_Dir"] = mountPoint

print(config["OP_Z_Mounted_Dir"])

return mountPoint

return ""

開發者ID:adwuard,項目名稱:OP_Manager,代碼行數:22,

示例5: prepare

​點讚 6

# 需要導入模塊: import psutil [as 別名]

# 或者: from psutil import disk_partitions [as 別名]

def prepare(cls, profile):

ret = super().prepare(profile)

if not ret["ok"]:

return ret

else:

ret["ok"] = False # Set back to false, so we can do our own checks here.

ret["active_mount_points"] = []

partitions = psutil.disk_partitions(all=True)

for p in partitions:

if p.device == "resticfs"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值