-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
59 lines (51 loc) · 1.23 KB
/
monitor.py
File metadata and controls
59 lines (51 loc) · 1.23 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
from cpuperc import get_cpu_perc
from memoryuse import get_mem_usage
from term_piechart import Pie
import plotext as plt
import time
t=[]
m=get_mem_usage()
print("Select the statistic to be displayed:\n1.CPU Usage for a window of time\n2.Memory Usage\n")
choice =int(input("Choice: "))
if choice==1:
r=int(input("\nEnter the time for window in seconds: "))
print("\nLoading...")
for x in range(r):
y=get_cpu_perc()
t.append(y)
liveuse =[]
plt.canvas_color('black')
plt.ylim(0,100)
plt.yticks([0,10,20,30,40,50,60,70,80,90,100])
max_points = 10
scroll_index=0
plt.plotsize(300,700)
for z in t:
liveuse.append(z)
scroll_index+=1
start=max(0,scroll_index-max_points)
end = scroll_index
if len(liveuse)>max_points:
liveuse.pop(0)
v=list(range(start,end))
s=[100]*len(t)
plt.clt()
plt.cld()
plt.plot(v,s,color= 'black')
plt.bar(v,liveuse, color = 'cyan')
plt.show()
time.sleep(1)
elif choice==2:
cached=m.cached+m.buffers
used = m.used
free = m.free
values=[
{"name":"used","value":used,"color":"cyan"},
{"name":"cache","value":cached,"color":"blue"},
{"name":"free","value":free,"color":"green"}
]
piechart=Pie(values,radius=5)
print(piechart)
print("\n")
else:
print("Invalid choice")