File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import psutil
2
+ import time
3
+ import os
4
+
5
+ def monitor_cpu_threshold (threshold ):
6
+ while True :
7
+ cpu_percent = psutil .cpu_percent (interval = 1 )
8
+ print (f"Current CPU Usage: { cpu_percent } %" )
9
+
10
+ if cpu_percent > threshold :
11
+ print ("CPU usage exceeds threshold!" )
12
+ # You can add more actions here, such as sending an email or notification.
13
+ # For simplicity, we'll just print an alert message.
14
+ os .system ("say 'High CPU usage detected!'" ) # macOS command to speak the message
15
+
16
+ time .sleep (10 ) # Wait for 10 seconds before checking again
17
+
18
+ if __name__ == "__main__" :
19
+ threshold_percent = 80 # Define the CPU usage threshold in percentage
20
+ monitor_cpu_threshold (threshold_percent )
Original file line number Diff line number Diff line change
1
+ # OS_interaction script
2
+
3
+ Short description of package/script
4
+
5
+ - This Script Was simple to setup
6
+ - Need import psutil,time,os
7
+
8
+
9
+ ## Setup instructions
10
+
11
+
12
+ Just Need to import psutil,time,os then run the OS_interaction.py file and for running python3 is must be installed!
13
+
14
+ ## Detailed explanation of script, if needed
15
+
16
+ This Script Is Only for OS_interaction use only!
You can’t perform that action at this time.
0 commit comments