Preview:
python
Edit
Run
Full Screen
Copy code
1def monitor_resources():
2    """Monitor system resources and take action if necessary"""
3    while True:
4        # Check CPU and GPU usage
5        cpu_usage = psutil.cpu_percent()
6        gpu_usage = psutil.gpu_percent()
7
8        # If CPU or GPU usage exceeds the threshold, stop mining and send an alert
9        if cpu_usage > 80 or gpu_usage > 80:
10            logger.warning("CPU or GPU usage too high! Stopping mining...")
11            os.system("killall miner")
12            send_email_alert("Resource Usage Alert", "CPU or GPU usage is too high!")
13            notify_user("CPU or GPU usage too high! Stopping mining...")
14
15        # Sleep for 10 seconds before checking again
16        time.sleep(10)
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