python查看内存使用率

2019-04-10  本文已影响0人  以我丶之姓
#! usr/bin/env python
#coding=utf-8

import psutil
def check_memory_state():  
    memory_utilization = psutil.virtual_memory().percent#获取内存使用率
    #phymem = psutil.virtual_memory()#获取本机内存信息
    #print phymem
    """ svmem(total=4294967296L, available=848031744L, percent=80.3, used=2268303360L, free=33693696L,
        active=814989312L, inactive=813240320L, wired=1453314048L)
        total:物理内存大小, available:可用内存, percent:内存使用率, used:物理已使用的内存大小, free:物理未使用的内存,
        active:, inactive:, wired:"""
    if memory_utilization >= memory_max_percent:
        print "System is lack of memory, almost reached ", memory_utilization
        check_OK = False
    else:
        print "System memory utilization:", memory_utilization
        check_OK = True
    return check_OK


if __name__ == "__main__":
    print "System Memory check!"
    if check_memory_state():
        print "Memory loading check pass!"
    else:
        print "Memory loading check fail"
上一篇下一篇

猜你喜欢

热点阅读