system.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:docklet 作者: unias 项目源码 文件源码
def get_system_loads():
        if 'last_cpu_sample' not in system_manager.__dict__:
            system_manager.last_cpu_sample = system_manager.get_cpu_sample()
            time.sleep(1)
        cpu_sample = system_manager.get_cpu_sample()
        (mem_free, mem_total) = system_manager.get_memory_sample()
        (swap_free, swap_total) = system_manager.get_swap_sample()
        ncpus = int(subprocess.getoutput("grep processor /proc/cpuinfo | wc -l"))
        cpu_free = ncpus - (cpu_sample[0] - system_manager.last_cpu_sample[0]) * 0.01 / (cpu_sample[1] - system_manager.last_cpu_sample[1])
        cpu_free = 0.0 if cpu_free <= 0.0 else cpu_free
        system_manager.last_cpu_sample = cpu_sample
        return {"mem_free": mem_free, "mem_total": mem_total, "swap_free": swap_free, "swap_total": swap_total, "cpu_free": cpu_free, "cpu_total": ncpus }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号