最近跑项目,老是内存不够导致宕机,于是折腾了小功能,达到实习监控
1.首先安装itchat包。
2.因为linux系统下不能弹出扫码框,那么可以选择自己打开图片的方式。需要将Python-3.6.2/lib/python3.6/site-packages/itchat/utils.py的第83行注释掉。这样扫码图片就会生成到你运行的当前目录下,直接打开扫码即可。
3.运行下面代码即可 /home/lh/software/Python-3.6.2/bin/python3.6 mem_detect.py
import itchat,time,subprocess,os itchat.login() while True: mem = subprocess.Popen('free -g',shell=True,stdout=subprocess.PIPE).stdout.read() remain = mem.decode().split()[9] time.sleep(5) if int(remain) < 1 : itchat.send(u'当前时间:%s \n内存不够,剩余 [%s] G' % (time.ctime(),remain),'filehelper') mem_detect.py (END)
好了,这样你的微信就能收到你的实时监控了。