Preview:
python
Edit
Run
Full Screen
Copy code
1import os
2import psutil
3import smtplib
4from email.message import EmailMessage
5
6def send_email_alert(subject, body):
7    msg = EmailMessage()
8    msg.set_content(body)
9    msg["Subject"] = subject
10    msg["From"] = "your_email_address"
11    msg["To"] = "your_email_address"
12
13    with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
14        server.login("your_email_address", "your_email_password")
15        server.send_message(msg)
16
17def monitor_resources():
18    while True:
19        cpu_usage = psutil.cpu_percent()
20        gpu_usage = psutil.gpu_percent()
21        memory_usage = psutil.virtual_memory().percent
22
23        if cpu_usage > 80 or gpu_usage > 80 or memory_usage > 80:
24            send_email_alert("Resource Usage Alert", "CPU or GPU usage is too high!")
25
26        time.sleep(10)
27
28if __name__ == "__main__":
29    check_permissions()
30    monitor_resources()
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter