穆琪的博客

一个程序员的自传

不间断获取树莓派内存信息监控脚本

# -*- coding: utf-8 -*
import psutil
import time
if __name__ == "__main__":
    while(True):
        memory_convent = 1024 * 1024
        mem = psutil.virtual_memory()
        print_str =  " The memory state as follows:\n"
        print_str = print_str + "   System memory total: "+str( mem.total/( memory_convent ) ) + " MB\n"
        print_str = print_str + "   System memory used: "+str( mem.used/( memory_convent ) ) + " MB\n"
        print_str = print_str + "   System memory free: "+str( mem.total/( memory_convent ) - mem.used/( memory_convent )) + "MB\n"
        # print_str = print_str + "   System memory buffer: "+str( mem.buffers/( memory_convent ) ) + " MB\n"
        # print_str = print_str + "   System memory cache:" +str( mem.cached/( memory_convent ) ) + " MB\n"
        a = (float)(mem.used/( memory_convent ))
        b = (float)(mem.total/( memory_convent ))
        c = "%.2f%%" % (a/b*100)
        print_str = print_str + "   Percentage:"+str( c )
        print print_str
        time.sleep(3)
© 鲁ICP备18041558号
Powered by Z-BlogPHP & Yiwuku.com