本文整理汇总了Python中psutil.disk_usage方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.disk_usage方法的具体用法?Python psutil.disk_usage怎么用?Python psutil.disk_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.disk_usage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [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
}
示例2: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [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
示例3: disk
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def disk():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.disk')
while True:
for path, label in PATHS:
disk_usage = psutil.disk_usage(path)
st = os.statvfs(path)
total_inode = st.f_files
free_inode = st.f_ffree
inode_percentage = int(100*(float(total_inode - free_inode) / total_inode))
c.gauge('%s.inodes.percent' % label, inode_percentage)
c.gauge('%s.total' % label, disk_usage.total)
c.gauge('%s.used' % label, disk_usage.used)
c.gauge('%s.free' % label, disk_usage.free)
c.gauge('%s.percent' % label, disk_usage.percent)
time.sleep(GRANULARITY)
示例4: crawl_disk_partitions
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def crawl_disk_partitions():
partitions = []
for partition in psutil.disk_partitions(all=True):
try:
pdiskusage = psutil.disk_usage(partition.mountpoint)
partitions.append((partition.mountpoint, DiskFeature(
partition.device,
100.0 - pdiskusage.percent,
partition.fstype,
partition.mountpoint,
partition.opts,
pdiskusage.total,
), 'disk'))
except OSError:
continue
return partitions
示例5: _run
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def _run(self):
while True:
perc_used = psutil.disk_usage('.').percent
if perc_used >= self._threshold:
if not self._low_disk.is_set():
self._low_disk.set()
LOG.critical(
'Disk space used above threshold ({}%), writing disabled'.format(self._threshold)
)
else:
if self._low_disk.is_set():
self._low_disk.clear()
LOG.info('Disk space used below threshold, writing restored')
gevent.sleep(60)
示例6: _check_disk_space
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def _check_disk_space(num_nodes):
free_disk_per_node = int(os.environ.get(
'MM_DISK_SPACE_PER_NODE',
10*1024 # default: 10MB per node
))
needed_disk = free_disk_per_node*num_nodes*1024
free_disk = psutil.disk_usage('.').free
LOG.debug('Disk space - needed: {} available: {}'.format(needed_disk, free_disk))
if free_disk <= needed_disk:
LOG.critical(
('Not enough space left on the device, available: {} needed: {}'
' - please delete traces, logs and old engine versions and restart').format(
free_disk, needed_disk
)
)
return None
return free_disk
示例7: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def getSystemInfo(info):
import readgpu
cuda, cudnn = readgpu.getCudaVersion()
info.update({
'cpu_count_phy': psutil.cpu_count(logical=False),
'cpu_count_log': psutil.cpu_count(logical=True),
'cpu_freq': psutil.cpu_freq().max,
'disk_total': psutil.disk_usage(cwd).total // 2**20,
'mem_total': psutil.virtual_memory().total // 2**20,
'python': readgpu.getPythonVersion(),
'torch': readgpu.getTorchVersion(),
'cuda': cuda,
'cudnn': cudnn,
'gpus': readgpu.getGPUProperties()
})
readgpu.uninstall()
del readgpu
return info
示例8: freeSpace
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def freeSpace(dir):
try:
import psutil
except:
if logger_availability:
logger.sendToLog("psutil in not installed!", "ERROR")
return None
try:
dir_space = psutil.disk_usage(dir)
free_space = dir_space.free
return int(free_space)
except Exception as e:
# log in to the log file
if logger_availability:
logger.sendToLog("persepolis couldn't find free space value:\n" + str(e), "ERROR")
return None
示例9: test_serialization
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def test_serialization(self):
def check(ret):
if json is not None:
json.loads(json.dumps(ret))
a = pickle.dumps(ret)
b = pickle.loads(a)
self.assertEqual(ret, b)
check(psutil.Process().as_dict())
check(psutil.virtual_memory())
check(psutil.swap_memory())
check(psutil.cpu_times())
check(psutil.cpu_times_percent(interval=0))
check(psutil.net_io_counters())
if LINUX and not os.path.exists('/proc/diskstats'):
pass
else:
if not APPVEYOR:
check(psutil.disk_io_counters())
check(psutil.disk_partitions())
check(psutil.disk_usage(os.getcwd()))
check(psutil.users())
示例10: test_disk_partitions_and_usage
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def test_disk_partitions_and_usage(self):
# test psutil.disk_usage() and psutil.disk_partitions()
# against "df -a"
def df(path):
out = sh('df -P -B 1 "%s"' % path).strip()
lines = out.split('\n')
lines.pop(0)
line = lines.pop(0)
dev, total, used, free = line.split()[:4]
if dev == 'none':
dev = ''
total, used, free = int(total), int(used), int(free)
return dev, total, used, free
for part in psutil.disk_partitions(all=False):
usage = psutil.disk_usage(part.mountpoint)
dev, total, used, free = df(part.mountpoint)
self.assertEqual(usage.total, total)
# 10 MB tollerance
if abs(usage.free - free) > 10 * 1024 * 1024:
self.fail("psutil=%s, df=%s" % (usage.free, free))
if abs(usage.used - used) > 10 * 1024 * 1024:
self.fail("psutil=%s, df=%s" % (usage.used, used))
示例11: test_disk_usage
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def test_disk_usage(self):
usage = psutil.disk_usage(os.getcwd())
self.assertEqual(usage._fields, ('total', 'used', 'free', 'percent'))
assert usage.total > 0, usage
assert usage.used > 0, usage
assert usage.free > 0, usage
assert usage.total > usage.used, usage
assert usage.total > usage.free, usage
assert 0 <= usage.percent <= 100, usage.percent
if hasattr(shutil, 'disk_usage'):
# py >= 3.3, see: http://bugs.python.org/issue12442
shutil_usage = shutil.disk_usage(os.getcwd())
tolerance = 5 * 1024 * 1024 # 5MB
self.assertEqual(usage.total, shutil_usage.total)
self.assertAlmostEqual(usage.free, shutil_usage.free,
delta=tolerance)
self.assertAlmostEqual(usage.used, shutil_usage.used,
delta=tolerance)
# if path does not exist OSError ENOENT is expected across
# all platforms
fname = self.get_testfn()
with self.assertRaises(FileNotFoundError):
psutil.disk_usage(fname)
示例12: test_against_df
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def test_against_df(self):
# test psutil.disk_usage() and psutil.disk_partitions()
# against "df -a"
def df(path):
out = sh('df -P -B 1 "%s"' % path).strip()
lines = out.split('\n')
lines.pop(0)
line = lines.pop(0)
dev, total, used, free = line.split()[:4]
if dev == 'none':
dev = ''
total, used, free = int(total), int(used), int(free)
return dev, total, used, free
for part in psutil.disk_partitions(all=False):
usage = psutil.disk_usage(part.mountpoint)
dev, total, used, free = df(part.mountpoint)
self.assertEqual(usage.total, total)
self.assertAlmostEqual(usage.free, free,
delta=TOLERANCE_DISK_USAGE)
self.assertAlmostEqual(usage.used, used,
delta=TOLERANCE_DISK_USAGE)
示例13: main
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def main():
templ = "%-17s %8s %8s %8s %5s%% %9s %s"
print(templ % ("Device", "Total", "Used", "Free", "Use ", "Type",
"Mount"))
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
usage = psutil.disk_usage(part.mountpoint)
print(templ % (
part.device,
bytes2human(usage.total),
bytes2human(usage.used),
bytes2human(usage.free),
int(usage.percent),
part.fstype,
part.mountpoint))
示例14: get_disk_info
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def get_disk_info():
disk_info = []
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
usage = psutil.disk_usage(part.mountpoint)
disk_info.append({
'device': part.device,
'total': usage.total,
'used': usage.used,
'free': usage.free,
'percent': usage.percent,
'fstype': part.fstype,
'mountpoint': part.mountpoint
})
return disk_info
示例15: available_bytes_at_path
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_usage [as 别名]
def available_bytes_at_path(path):
"""Get the available disk space in a given directory.
Args:
path (str): Directory path to check.
Returns:
int: Available space, in bytes
Raises:
OSError: if the specified path does not exist or is not readable.
"""
if not os.path.exists(path):
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), path)
if not os.path.isdir(path):
raise OSError(errno.ENOTDIR, os.strerror(errno.ENOTDIR), path)
available = disk_usage(path).free
logger.debug("There appears to be %s available at %s",
pretty_bytes(available), path)
return available