Are you worried that there is not enough memory or the CPU is overloaded to cause downtime? 8 lines of code automatically monitor system memory and notify WeChat in time, monitor whatever you want to monitor.

Recently, when running a project, there is always insufficient memory, which leads to downtime, so I have tossed small functions to achieve practice monitoring.

1. First install the itchat package.

2. Because the scan code box cannot pop up under the Linux system, you can choose the way to open the picture yourself. Line 83 of Python-3.6.2/lib/python3.6/site-packages/itchat/utils.py needs to be commented out. In this way, the scan code picture will be generated in the current directory where you are running, and you can directly open the scan code.


3. Run the following code /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'Current time: %s \nInsufficient memory, remaining [%s] G' % (time.ctime(),remain),'filehelper')
mem_detect.py (END)

Well, so that your WeChat can receive your real-time monitoring.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325570683&siteId=291194637