本文整理汇总了Python中psutil.swap_memory方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.swap_memory方法的具体用法?Python psutil.swap_memory怎么用?Python psutil.swap_memory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.swap_memory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [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
示例2: memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def memory():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.memory')
while True:
swap = psutil.swap_memory()
c.gauge('swap.total', swap.total)
c.gauge('swap.used', swap.used)
c.gauge('swap.free', swap.free)
c.gauge('swap.percent', swap.percent)
virtual = psutil.virtual_memory()
c.gauge('virtual.total', virtual.total)
c.gauge('virtual.available', virtual.available)
c.gauge('virtual.used', virtual.used)
c.gauge('virtual.free', virtual.free)
c.gauge('virtual.percent', virtual.percent)
c.gauge('virtual.active', virtual.active)
c.gauge('virtual.inactive', virtual.inactive)
c.gauge('virtual.buffers', virtual.buffers)
c.gauge('virtual.cached', virtual.cached)
time.sleep(GRANULARITY)
示例3: test_serialization
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [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())
示例4: test_swap_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def test_swap_memory(self):
out = sh('/usr/sbin/lsps -a')
# From the man page, "The size is given in megabytes" so we assume
# we'll always have 'MB' in the result
# TODO maybe try to use "swap -l" to check "used" too, but its units
# are not guaranteed to be "MB" so parsing may not be consistent
matchobj = re.search("(?P<space>\S+)\s+"
"(?P<vol>\S+)\s+"
"(?P<vg>\S+)\s+"
"(?P<size>\d+)MB", out)
self.assertIsNotNone(
matchobj, "lsps command returned unexpected output")
total_mb = int(matchobj.group("size"))
MB = 1024 ** 2
psutil_result = psutil.swap_memory()
# we divide our result by MB instead of multiplying the lsps value by
# MB because lsps may round down, so we round down too
self.assertEqual(int(psutil_result.total / MB), total_mb)
示例5: test_no_vmstat_mocked
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def test_no_vmstat_mocked(self):
# see https://github.com/giampaolo/psutil/issues/722
with mock_open_exception(
"/proc/vmstat",
IOError(errno.ENOENT, 'no such file or directory')) as m:
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
ret = psutil.swap_memory()
assert m.called
self.assertEqual(len(ws), 1)
w = ws[0]
assert w.filename.endswith('psutil/_pslinux.py')
self.assertIn(
"'sin' and 'sout' swap memory stats couldn't "
"be determined and were set to 0",
str(w.message))
self.assertEqual(ret.sin, 0)
self.assertEqual(ret.sout, 0)
示例6: test_swap_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def test_swap_memory(self):
out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH'])
lines = out.strip().split('\n')[1:]
if not lines:
raise ValueError('no swap device(s) configured')
total = free = 0
for line in lines:
line = line.split()
t, f = line[-2:]
total += int(int(t) * 512)
free += int(int(f) * 512)
used = total - free
psutil_swap = psutil.swap_memory()
self.assertEqual(psutil_swap.total, total)
self.assertEqual(psutil_swap.used, used)
self.assertEqual(psutil_swap.free, free)
示例7: test_swap_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def test_swap_memory(self):
out = sh('/usr/sbin/lsps -a')
# From the man page, "The size is given in megabytes" so we assume
# we'll always have 'MB' in the result
# TODO maybe try to use "swap -l" to check "used" too, but its units
# are not guaranteed to be "MB" so parsing may not be consistent
matchobj = re.search(r"(?P<space>\S+)\s+"
r"(?P<vol>\S+)\s+"
r"(?P<vg>\S+)\s+"
r"(?P<size>\d+)MB", out)
self.assertIsNotNone(
matchobj, "lsps command returned unexpected output")
total_mb = int(matchobj.group("size"))
MB = 1024 ** 2
psutil_result = psutil.swap_memory()
# we divide our result by MB instead of multiplying the lsps value by
# MB because lsps may round down, so we round down too
self.assertEqual(int(psutil_result.total / MB), total_mb)
示例8: test_swapmem_sout
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def test_swapmem_sout(self):
vmstat_val = vm_stat("Pageout")
psutil_val = psutil.swap_memory().sout
self.assertEqual(psutil_val, vmstat_val)
# Not very reliable.
# def test_swapmem_total(self):
# out = sh('sysctl vm.swapusage')
# out = out.replace('vm.swapusage: ', '')
# total, used, free = re.findall('\d+.\d+\w', out)
# psutil_smem = psutil.swap_memory()
# self.assertEqual(psutil_smem.total, human2bytes(total))
# self.assertEqual(psutil_smem.used, human2bytes(used))
# self.assertEqual(psutil_smem.free, human2bytes(free))
# --- network
示例9: main
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def main():
virt = psutil.virtual_memory()
swap = psutil.swap_memory()
templ = "%-7s %10s %10s %10s %10s %10s %10s"
print(templ % ('', 'total', 'used', 'free', 'shared', 'buffers', 'cache'))
print(templ % (
'Mem:',
int(virt.total / 1024),
int(virt.used / 1024),
int(virt.free / 1024),
int(getattr(virt, 'shared', 0) / 1024),
int(getattr(virt, 'buffers', 0) / 1024),
int(getattr(virt, 'cached', 0) / 1024)))
print(templ % (
'Swap:', int(swap.total / 1024),
int(swap.used / 1024),
int(swap.free / 1024),
'',
'',
''))
示例10: sysmetrics_update
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def sysmetrics_update(self, global_step=None):
if global_step is None:
global_step = time.strftime("%x_%X")
mem = psutil.virtual_memory()
mem_used = (mem.total - mem.available)
gpu_vals = self.gpu_logger.get_vals()
rel_time = time.time() - self.sysmetrics_start_time
self.sysmetrics.loc[len(self.sysmetrics)] = [global_step, rel_time,
psutil.cpu_percent(), mem_used / 1024 ** 3,
mem_used / mem.total * 100,
psutil.swap_memory().used / 1024 ** 3,
int(gpu_vals['gpu_graphics_util']),
*[torch.cuda.memory_allocated(d) / 1024 ** 3 for d in
range(torch.cuda.device_count())],
*[torch.cuda.memory_cached(d) / 1024 ** 3 for d in
range(torch.cuda.device_count())]
]
return self.sysmetrics.loc[len(self.sysmetrics) - 1].to_dict()
示例11: json_charts
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def json_charts(self, req):
""" Return charting data.
"""
disk_used, disk_total, disk_detail = 0, 0, []
for disk_usage_path in self.cfg.disk_usage_path.split(os.pathsep):
disk_usage = self.guarded(psutil.disk_usage, os.path.expanduser(disk_usage_path.strip()))
if disk_usage:
disk_used += disk_usage.used
disk_total += disk_usage.total
disk_detail.append((disk_usage.used, disk_usage.total))
data = dict(
engine = self.json_engine(req),
uptime = time.time() - psutil.BOOT_TIME, # pylint: disable=no-member
fqdn = self.guarded(socket.getfqdn),
cpu_usage = self.guarded(psutil.cpu_percent, 0),
ram_usage = self.guarded(psutil.virtual_memory),
swap_usage = self.guarded(psutil.swap_memory),
disk_usage = (disk_used, disk_total, disk_detail) if disk_total else None,
disk_io = self.guarded(psutil.disk_io_counters),
net_io = self.guarded(psutil.net_io_counters),
)
return data
示例12: get_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def get_memory():
memory = dict()
virtual = psutil.virtual_memory()
swap = psutil.swap_memory()
memory['virtual_total'] = '%.2fMB' % (virtual.total/1024/1024)
memory['virtual_available'] = '%.2fMB' % (virtual.available/1024/1024)
memory['virtual_percent'] = str(virtual.percent)+'%'
memory['virtual_used'] = '%.2fMB' % (virtual.used/1024/1024)
memory['virtual_free'] = '%.2fMB' % (virtual.free/1024/1024)
memory['virtual_active'] = '%.2fMB' % (virtual.active/1024/1024)
memory['virtual_inactive'] = '%.2fMB' % (virtual.inactive/1024/1024)
memory['virtual_buffers'] = '%.2fMB' % (virtual.buffers/1024/1024)
memory['virtual_cached'] = '%.2fMB' % (virtual.cached/1024/1024)
memory['virtual_shared'] = '%.2fMB' % (virtual.shared/1024/1024)
memory['swap_total'] = '%.2fMB' % (swap.total/1024/1024)
memory['swap_used'] = '%.2fMB' % (swap.used/1024/1024)
memory['swap_free'] = '%.2fMB' % (swap.free/1024/1024)
memory['swap_percent'] = str(swap.percent)+'%'
memory['swap_sin'] = '%.2fMB' % (swap.sin/1024/1024)
memory['swap_sout'] = '%.2fMB' % (swap.sout/1024/1024)
return memory
示例13: _swap_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def _swap_memory(self):
swap = psutil.swap_memory()
return {
'total': swap.total,
'used': swap.used,
'free': swap.free,
'percent': swap.percent,
'sin': swap.sin,
'sout': swap.sout,
}
示例14: _get_available_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def _get_available_memory(self):
return psutil.swap_memory().free
示例15: _get_total_memory
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import swap_memory [as 别名]
def _get_total_memory(self):
return psutil.swap_memory().total