def get_system_status(memory_total=False, memory_total_actual=False,
memory_total_usage=False, memory_total_free=False,
all_pids=False, swap_memory=False, pid=False):
"""
Parameters
----------
threads: bool
return dict {id: (user_time, system_time)}
memory_maps: bool
return dict {path: rss}
Note
----
All memory is returned in `MiB`
To calculate memory_percent:
get_system_status(memory_usage=True) / get_system_status(memory_total=True) * 100
"""
import psutil
# ====== general system query ====== #
if memory_total:
return psutil.virtual_memory().total / float(2 ** 20)
if memory_total_actual:
return psutil.virtual_memory().available / float(2 ** 20)
if memory_total_usage:
return psutil.virtual_memory().used / float(2 ** 20)
if memory_total_free:
return psutil.virtual_memory().free / float(2 ** 20)
if swap_memory:
tmp = psutil.swap_memory()
tmp.total /= float(2 ** 20)
tmp.used /= float(2 ** 20)
tmp.free /= float(2 ** 20)
tmp.sin /= float(2**20)
tmp.sout /= float(2**20)
return tmp
if all_pids:
return psutil.pids()
if pid:
return os.getpid()
评论列表
文章目录