还怕内存不够或者cpu过度负载导致宕机吗?8行代码自动监控系统内存并及时微信通知,想监控啥就监控啥。
2018-03-30 13:58
316 查看
最近跑项目,老是内存不够导致宕机,于是折腾了小功能,达到实习监控
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.pyimport 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)
好了,这样你的微信就能收到你的实时监控了。
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.pyimport 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)
好了,这样你的微信就能收到你的实时监控了。
相关文章推荐
- 老李分享:apache日志分析及系统cpu,内存,负载情况监控
- 系统的负载与CPU、内存、硬盘、用户数监控
- 老李分享:apache日志分析及系统cpu,内存,负载情况监控 2
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- centos inux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- shell脚本监控系统负载、CPU和内存使用情况
- centos 6.4 系统CPU,内存,负载,IO监控脚本
- linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- Linux 系统CPU,内存,负载,IO监控脚本
- 利用shell脚本来监控linux系统的负载与CPU和内存使用情况
- Linux系统的负载与CPU、内存、硬盘、用户数监控的shell脚本
- shell脚本监控系统负载、CPU和内存使用情况
- linux 系统的负载与CPU、内存、硬盘、用户数监控脚本[marked]
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本 推荐
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本