-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (46 loc) · 1.5 KB
/
main.py
File metadata and controls
51 lines (46 loc) · 1.5 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
import psutil as ps
def getpid(process_name):
for proc in ps.process_iter(['pid', 'name']):
if proc.info['name'].lower() == process_name.lower():
return print(f"Pid: {proc.info['pid']}")
return None
def getTempSensor():
return ps.sensors_temperatures()
def getCPUUsage():
return ps.cpu_percent()
def getMemoryUsage():
return ps.virtual_memory().percent
def getDiskUsage():
return ps.disk_usage('/')
def getProcessList():
return '\n '.join([f"PID: {proc.info['pid']}, Name: {proc.info['name']}, CPU: {proc.info['cpu_percent']}%, Memory: {proc.info['memory_percent']}%"
for proc in ps.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent'])])
cpu_usage = getCPUUsage()
memory_usage = getMemoryUsage()
disk_usage = getDiskUsage()
process_list = getProcessList()
while True:
select = input("""
Choose an option:
1) CPU Usage
2) Memory Usage
3) Disk Usage
4) Process List
5) Process Pid
6) Exit
Choice: """)
if select == "1":
print(f"CPU Usage: {cpu_usage}%")
elif select == "2":
print(f"Memory Usage: {memory_usage}%")
elif select == "3":
print(f"Disk Usage: {disk_usage}%")
elif select == "4":
print(f"Process List:\n{process_list}")
elif select == "5":
getpid(process_name=input("process_name: "))
elif select == "6":
print("exit")
break
else:
print("Invalid choice!")