Skip to content

Commit 6d05c3e

Browse files
authored
Simple program to check CPU overload
Using psutil library, checks if CPU is over % usage
0 parents  commit 6d05c3e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cpu_usage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
import psutil
3+
4+
def check_cpu_usage(percent):
5+
usage = psutil.cpu_percent(1)
6+
print("DEBUG: usage {}".format(usage))
7+
return usage < percent
8+
9+
if not check_cpu_usage(75):
10+
print("ERROR: CPU is overloaded")
11+
else:
12+
print("Everything ok")

0 commit comments

Comments
 (0)