python 监控linux内存脚本

释放双眼,带上耳机,听听看~!

#!/usr/bin/env python
# -*- coding:utf-8 -*- 
from future import division 
import re,time
localtime = time.asctime(time.localtime(time.time()))
def mem_stat():
f = open('/proc/meminfo')
lines = f.readlines()
f.close()
memtotal = re.findall(r"\d+",lines[0])
mem_total = "".join(memtotal)
memfree = re.findall(r"\d+",lines[1])
mem_free = "".join(memfree)
membuffers = re.findall(r"\d+",lines[3])
mem_buffers = "".join(membuffers)
memcache = re.findall(r"\d+",lines[4])
mem_cache = "".join(memcache)
mem_usage_per = (int(mem_free) + int(mem_buffers) + int(mem_cache))/int(mem_total)*100
mem_free_per = int(mem_free)/int(mem_total)*100
print "%s  内存使用率(free/total):%s,内存占用率:%s"%(localtime,mem_free_per,mem_usage_per)
mem_stat()

给TA打赏
共{{data.count}}人
人已打赏
安全技术

c++ list, vector, map, set 区别与用法比较

2022-1-11 12:36:11

安全漏洞

Tomcat 又爆出两个重要漏洞

2012-1-17 11:12:22

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索