-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
93 lines (75 loc) · 2.72 KB
/
monitor.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import psutil
import cpuinfo
import platform
import time
import datetime
import GPUtil
class CPU:
def __init__(self):
cpuInfo = cpuinfo.get_cpu_info()
self.name = cpuInfo['brand_raw']
self.cores = psutil.cpu_count(False)
self.logical_cores = psutil.cpu_count()
self.base_frequency = round(float(cpuInfo["hz_advertised_friendly"].replace(" GHz", "")), 2)
self.architecture = cpuInfo["arch"]
@staticmethod
def get_usage():
return psutil.cpu_percent()
class System:
def __init__(self):
self.name = platform.system()
self.release = platform.release()
self.version = platform.version()
@staticmethod
def get_uptime():
timeSinceBootSeconds = int(time.time()) - int(psutil.boot_time())
timeSinceBootReadable = datetime.timedelta(seconds = timeSinceBootSeconds)
return timeSinceBootReadable
class Memory:
def __init__(self):
memory = psutil.virtual_memory()
self.total = round(memory.total / 1024 / 1024 / 1024, 2)
def get_used_memory(self):
memory = psutil.virtual_memory()
return round(memory.used / 1024 / 1024 / 1024, 2)
def get_free_memory(self):
return round(self.total - self.get_used_memory(), 2)
def get_memory_usage(self):
return round((self.total - self.get_free_memory()) / self.total * 100 , 1)
class GPU:
def __init__(self):
self.check_gpu()
def check_gpu(self):
try:
GPUtil.getGPUs()
except:
self.gpu = "Unknown GPU"
return self.gpu
else:
self.gpu = GPUtil.getGPUs()[0]
self.name = self.gpu.name
self.total_memory = round(self.gpu.memoryTotal / 1024, 2)
def get_used_memory(self):
return round(self.gpu.memoryUsed / 1024, 2)
def get_free_memory(self):
return round((self.gpu.memoryTotal - self.gpu.memoryUsed) / 1024, 2)
def get_memory_usage(self):
return round(self.gpu.memoryUtil * 100, 1)
def get_load(self):
return round(self.gpu.load * 100, 1)
def get_temperature(self):
return self.gpu.temperature
class Storage():
@staticmethod
def get_drives():
partitions = psutil.disk_partitions()
drives = []
for partion in partitions:
drive = psutil.disk_usage(partion.device)
drives.append([partion.device,
round(drive.total / 1024 / 1024 / 1024, 2),
round(drive.used / 1024 / 1024 / 1024, 2),
round(drive.free / 1024 / 1024 / 1024, 2),
drive.percent])
return drives
gpu = GPU()