-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
74 lines (63 loc) · 1.88 KB
/
monitor.py
File metadata and controls
74 lines (63 loc) · 1.88 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import psutil
import time
import MacTmp
import os
class SysMonitor:
def __init__(self, period=5):
self.period = period
def memory(self):
"""
Getting system memory stats
"""
print('Memory usage: ', psutil.virtual_memory()[2], '%')
def cpu(self):
"""
Getting system CPU stats
"""
print('System CPU percentage: ', psutil.cpu_percent(), '%')
print('CPU percentage per core: ', psutil.cpu_percent(percpu=True))
def loadavg(self):
"""
Gets the system load average
"""
print('Load average: ', psutil.getloadavg())
def temperature(self):
"""
Gets the CPU temperature
"""
# print('CPU temperature: ', psutil.sensors_temperatures()) for Linux and FreeBSD only
print('CPU temperature: ', MacTmp.CPU_Temp(), 'C')
def battery(self):
"""
Getting battery status
"""
print('Battery status: ', psutil.sensors_battery())
def disk_util(self):
"""
Disk usage information
"""
print('Disk usage: ', psutil.disk_usage('/dev/disk1s5'))
def process_monitor(self):
"""
Gets a process listing showing the cpu usage
"""
print('Process Listing: ')
for process in psutil.process_iter():
process_info = process.as_dict(attrs=['name', 'cpu_percent'])
if process_info['cpu_percent'] and process_info['cpu_percent'] > 10:
print(process_info)
if __name__ == '__main__':
repeat = 0
a = SysMonitor()
while True:
os.system('clear')
repeat += 1
print(f'Repeat #{repeat}, {a.period} seconds timeout \n')
a.memory()
a.cpu()
a.loadavg()
a.temperature()
# a.battery()
# a.disk_util()
a.process_monitor()
time.sleep(a.period)