-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_manager.py
More file actions
35 lines (25 loc) · 894 Bytes
/
task_manager.py
File metadata and controls
35 lines (25 loc) · 894 Bytes
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
# =============
# Task Manager
# =============
import psutil
def get_system_resources():
cpu_usage = psutil.cpu_percent(interval=1)
mem = psutil.virtual_memory()
mem_used = mem.used / (1024**3)
mem_tot = mem.total / (1024**3)
stats = {
"CPU" : f"{cpu_usage}%",
"Memory" : f"{mem_used:.2f} / {mem_tot:.2f} GB"
}
for partition in psutil.disk_partitions():
try:
usage = psutil.disk_usage(partition.mountpoint)
used_gb = usage.used / (1024**3)
total_gb = usage.total / (1024**3)
stats[f"Disk ({partition.mountpoint})"] = (f"{used_gb : .2f} / {total_gb:.2f} GB")
except PermissionError:
continue
return stats
resource = get_system_resources()
for name,usage in resource.items():
print(f"{name} : {usage}")