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}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

用node.js从零开始去写一个简单的爬虫

2021-12-21 16:36:11

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