Improved Response: The updated code includes the - Blackbox
Mon May 13 2024 03:55:03 GMT+0000 (Coordinated Universal Time)
Saved by
@mohmdemoon
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()
content_copyCOPY
https://www.blackbox.ai/share/6eeb27fe-592c-4f6e-ae46-767ca4334f80
Comments