-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
64 lines (60 loc) · 1.62 KB
/
process.py
File metadata and controls
64 lines (60 loc) · 1.62 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
import subprocess
import csv
from StringIO import StringIO
def Top10ProcessesMemory():
"""
"""
p=subprocess.Popen("ps -eo user,cmd,%mem --sort=-%mem | head -n 5",shell=True,stdout=subprocess.PIPE)
q=subprocess.Popen("ps -eo user,cmd,%cpu --sort=-%cpu | head -n 5",shell=True,stdout=subprocess.PIPE)
memory = p.communicate()[0]
cpu = q.communicate()[0]
memory = memory.strip(" ")
cpu = cpu.strip(" ")
f = StringIO(memory)
f1 = StringIO(cpu)
i=0
values=[]
label=[]
valuesCpu=[]
labelCpu=[]
memoryReader = csv.reader(f, delimiter=' ',skipinitialspace=True)
for row in memoryReader:
if(i==0):
i+=1
continue
else:
label.append('{0} {1}'.format(row[0],row[1]))
values.append(float(row[-1]))
print values,label
i=0
cpuReader = csv.reader(f1, delimiter=' ',skipinitialspace=True)
for row in cpuReader:
if(i==0):
i+=1
continue
else:
labelCpu.append('{0} {1}'.format(row[0],row[1]))
valuesCpu.append(float(row[-1]))
jsfile=open("process.js","w+")
jsfile.write("""
var procMemory=[{{
values: {0},
labels: {1},
type: 'pie'
}}];
var procCPU=[{{
values: {2},
labels: {3},
type: 'pie'
}}];
var layoutMemory = {{
width:500,
height:400,
title:'Top 5 Process Consumers (Memory)'
}};
var layoutCPU = {{
width:500,
height:400,
title:'Top 5 Process Consumers (CPU)'
}};""".format(values,label,valuesCpu,labelCpu))
jsfile.close()