欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > python邮件告警

python邮件告警

2025/11/11 14:50:34 来源:https://blog.csdn.net/2401_83945639/article/details/140722772  浏览:    关键词:python邮件告警

这里写的是俩个模块,需要调用模块,但是俩个模块都必须在同一目录下

import subprocess
import mail 
def use():a=subprocess.getoutput("""df -h | grep '^/dev/m' | awk '{print $5}'| tr -d "%" """)a= int(a)if a > 20:print("警告")mailelse:print("正常")
use()
import yagmail
yag = yagmail.SMTP(user="2996xxxxx@qq.com",password="xxxxxxxxxxxxx",host="smtp.qq.com",port=465,smtp_ssl=True,)
yag.send(to="12345678@qq.com", subject="提示", contents=f"你的根分区使用情况过高")
print("b")

监控cpu,内存

import subprocess
# 监控1 分钟的cpu负载
def cpuload():cpu_data = subprocess.getoutput('''uptime | awk '{print $(NF-2)}' | tr -d ","''')cpu_data = float(cpu_data) * 100cpus = subprocess.getoutput("""lscpu  | grep '^CPU(s):' | awk '{print $2}'""")cpus = int(cpus)if cpu_data / cpus > 100:print("cpu 负载过高")# 监控内存使用百分比
def free():total,free = subprocess.getoutput("""free -m | awk 'NR==2{print $2,$4}'""").split(" ")total,free = int(total),int(free)if free / total * 100 < 98:print(free / total * 100)print("内存剩余空间不足")
# 监控当前/分的的剩余空间free()

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词