-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataProcessor.py
149 lines (123 loc) · 8.47 KB
/
DataProcessor.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from constants import machines, alpha, markersize, markers
from Utils import *
from HTMLGenerator import *
import numpy as np
import glob
import matplotlib.pyplot as plt
#TODO: handle crashed host / host not available
class DataProcessor:
def __init__(self):
self.machineData = [ ['Host', '# of Users', 'Load Average'] ]
self.times = [ ]
self.htmlGenerator = HTMLGenerator()
# sourced from: https://uwaterloo.ca/computer-science-computing-facility/teaching-hosts
self.machineSpecs = [
['Host', 'CPU Type', '# of CPUs', 'Cores/CPU', 'Threads/Core', 'RAM (GB)', 'Make', 'Model'],
[machines[0], 'Intel(R) Xeon(R) Gold 6148 @ 2.40GHz', 2, 20, 2, 384,'Supermicro','SYS-1029U-E1CR25M'],
[machines[1], 'Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz', 2, 16, 2, 256, 'Dell Inc.', 'PowerEdge R730'],
[machines[2], 'AMD EPYC 7532', 2, 32, 2, 256, 'Dell Inc.', 'PowerEdge R7525'],
[machines[3], 'AMD EPYC 7532', 2, 32, 2, 256, 'Dell Inc.', 'PowerEdge R7525']
]
self.graphData = {
machines[0]: {'numUsers':0, 'loadAverage':0},
machines[1]: {'numUsers':0, 'loadAverage':0},
machines[2]: {'numUsers':0, 'loadAverage':0},
machines[3]: {'numUsers':0, 'loadAverage':0}
}
if not glob.glob('*.npz'): # no historical data available
# machine_x, machine_i_y, 0 <= i < 4
print('No historical data found...')
time = np.array([])
machine0_users, machine0_loadAverage = np.array([]), np.array([])
machine1_users, machine1_loadAverage = np.array([]), np.array([])
machine2_users, machine2_loadAverage = np.array([]), np.array([])
machine3_users, machine3_loadAverage = np.array([]), np.array([])
np.savez('timeSeries_numUsers.npz', time=time, machine0_users=machine0_users, machine1_users=machine1_users,
machine2_users=machine2_users, machine3_users=machine3_users)
np.savez('timeSeries_loadAverage.npz', time=time, machine0_loadAverage=machine0_loadAverage, machine1_loadAverage=machine1_loadAverage,
machine2_loadAverage=machine2_loadAverage, machine3_loadAverage=machine3_loadAverage)
def process(self, machine, data):
def getNumUsers():
top_users = data[0].split(',')[2].split(' ')
return float(top_users[len(top_users)-2])
def getLoadAverage():
loadAverage = ['0']*3
load_avg = data[0].split(',')[3:]
loadAverage[0] = float(load_avg[0].split(' ')[-1]) # 1 minute
loadAverage[1] = float(load_avg[1]) # 5 minutes
loadAverage[2] = float(load_avg[2][:-1]) # 15 minutes
return loadAverage[1]
def getCPU_Usage():
CPU_usage = ['0']*3
usage = data[2].split(',')[:4]
CPU_usage[0] = float(usage[0].split(' ')[2]) # user
CPU_usage[1] = float(usage[1].split(' ')[2]) # sys
CPU_usage[2] = float(usage[3].split(' ')[1]) # idle
return CPU_usage
def getTime():
time = data[0].split('-')[1].split('up')[0][1:-1]
return time # time of top
numUsers = getNumUsers()
loadAverage = getLoadAverage()
self.times.append(getTime())
self.machineData.append([machine, numUsers, loadAverage])
self.graphData[machine] = {'numUsers':numUsers, 'loadAverage':loadAverage}
def updateCharts(self):
meanTime = Utils.meanTime(self.times)
numUsers_data = np.load('timeSeries_numUsers.npz')
loadAverage_data = np.load('timeSeries_loadAverage.npz')
time = numUsers_data['time'] # same as loadAverage_data['time']
time = np.append(time,meanTime)
machine0_users = numUsers_data['machine0_users']
machine0_users = np.append(machine0_users,self.graphData[machines[0]]['numUsers'])
machine1_users = numUsers_data['machine1_users']
machine1_users = np.append(machine1_users,self.graphData[machines[1]]['numUsers'])
machine2_users = numUsers_data['machine2_users']
machine2_users = np.append(machine2_users,self.graphData[machines[2]]['numUsers'])
machine3_users = numUsers_data['machine3_users']
machine3_users = np.append(machine3_users,self.graphData[machines[3]]['numUsers'])
np.savez('timeSeries_numUsers.npz', time=time, machine0_users=machine0_users, machine1_users=machine1_users,
machine2_users=machine2_users, machine3_users=machine3_users)
machine0_loadAverage = loadAverage_data['machine0_loadAverage']
machine0_loadAverage = np.append(machine0_loadAverage,self.graphData[machines[0]]['loadAverage'])
machine1_loadAverage = loadAverage_data['machine1_loadAverage']
machine1_loadAverage = np.append(machine1_loadAverage,self.graphData[machines[1]]['loadAverage'])
machine2_loadAverage = loadAverage_data['machine2_loadAverage']
machine2_loadAverage = np.append(machine2_loadAverage,self.graphData[machines[2]]['loadAverage'])
machine3_loadAverage = loadAverage_data['machine3_loadAverage']
machine3_loadAverage = np.append(machine3_loadAverage,self.graphData[machines[3]]['loadAverage'])
np.savez('timeSeries_loadAverage.npz', time=time, machine0_loadAverage=machine0_loadAverage, machine1_loadAverage=machine1_loadAverage,
machine2_loadAverage=machine2_loadAverage, machine3_loadAverage=machine3_loadAverage)
m0, = plt.plot(time, machine0_users, label='1804-002', linestyle=':', marker=markers[0], markersize=markersize, alpha=alpha)
m1, = plt.plot(time, machine1_users, label='1804-010', linestyle='-.', marker=markers[1], markersize=markersize, alpha=alpha)
m2, = plt.plot(time, machine2_users, label='2004-002', linestyle='--', marker=markers[2], markersize=markersize, alpha=alpha)
m3, = plt.plot(time, machine3_users, label='2004-004', marker=markers[3], markersize=markersize)
plt.legend(handles=[m0, m1, m2, m3], bbox_to_anchor=(1.05, 1), loc='upper left', fontsize='xx-small')
ax = plt.gca()
ax.axes.xaxis.set_ticks([])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
plt.title('Active Users on CS Student Servers')
plt.savefig('users_vs_time.png', dpi=300, bbox_inches='tight')
plt.close()
m0, = plt.plot(time, machine0_loadAverage, label='1804-002', linestyle=':', marker=markers[0],
markersize=markersize, alpha=alpha)
m1, = plt.plot(time, machine1_loadAverage, label='1804-010', linestyle='-.', marker=markers[1],
markersize=markersize, alpha=alpha)
m2, = plt.plot(time, machine2_loadAverage, label='2004-002', linestyle='--', marker=markers[2],
markersize=markersize, alpha=alpha)
m3, = plt.plot(time, machine3_loadAverage, label='2004-004', marker=markers[3], markersize=markersize, alpha=alpha)
plt.legend(handles=[m0, m1, m2, m3], bbox_to_anchor=(1.05, 1), loc='upper left', fontsize='xx-small')
ax = plt.gca()
ax.axes.xaxis.set_ticks([])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
plt.title('CS Student Server Load Average')
plt.savefig('load_vs_time.png', dpi=300, bbox_inches='tight')
plt.close()
HTMLGenerator.generatePage(self.machineSpecs,self.machineData,meanTime)
self.machineData = [self.machineData[0]]