-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_health_check.py
More file actions
35 lines (30 loc) · 1.13 KB
/
system_health_check.py
File metadata and controls
35 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# import system libraries
import psutil, shutil
def check_disk_usage():
''' check free disk space'''
print()
print('============== TEST PARAMETERS! ===============')
check = shutil.disk_usage("C:/")
free = check.free/check.total*100
print('Free Disk Space:', free,'GB')
return free > 30
def check_cpu_usage():
'''Check if CPU is overloaded.'''
for i in range(1,30):
usage = psutil.cpu_percent(interval=i)
print("CPU Usage:",usage,'%')
if usage < 75:
return True
else:
return False
def health_check():
'''Check health of system'''
disk_status = check_disk_usage()
cpu_status = check_cpu_usage()
print()
print('============== TEST OUTCOME! ===============')
if disk_status != True and cpu_status != True:
return ("ERROR!: Test Fail!\nIs Free Disk Space > 30 GB: {}. \nIs CPU Usage < 75%: {}".format(disk_status,cpu_status))
else:
return ("Success!: Test Pass!\nIs Free disk space > 30 GB: {}. \nIs CPU usage < 75%: {}.".format(disk_status,cpu_status))
print(health_check())