-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_iostat.py
executable file
·349 lines (251 loc) · 10.8 KB
/
plot_iostat.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#! /usr/bin/env python3
###################################################
#
# file: storage_metrics.py
#
# @Author: Iacovos G. Kolokasis
# @Version: 20-02-2020
# @email: [email protected]
#
# Write here brief explanation about your code
#
###################################################
import optparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import config
import os
# Parse input arguments
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-i", "--input", dest="input", metavar="FILE", help="Input file")
parser.add_option("-o", "--outputPath", metavar="PATH", dest="outputPath", default="output.svg", help="Output Path")
parser.add_option("-s", "--storage", dest="storage", help="Storage device e.g sdb, nvme0n1")
(options, args) = parser.parse_args()
if not os.path.exists(options.outputPath):
os.makedirs(options.outputPath)
# Open input file
inputFile = open(options.input, 'r')
flag = 0
userCPU = [] # User CPU Utilization
systemCPU = [] # System CPU Utilization
iowaitCPU = [] # Iowait CPU
idleCPU = [] # Idle CPU
rRqMerge = [] # Read Request Merge
wRqMerge = [] # Write Request Merge
readThroughput = [] # Read Throughput Storage Device
writeThroughput = [] # Write Throughput Storage Device
avgRqSize = [] # Average Req. Size
avgQuSize = [] # Average Queue Size
util = [] # Storage Device Utilization
for line in inputFile.readlines():
repLine = line.replace(',', '.')
if flag == 1:
# Reset flag
flag = 0
# Append each metric values to the proper array
userCPU.append(float(repLine.split()[0]))
systemCPU.append(float(repLine.split()[2]))
iowaitCPU.append(float(repLine.split()[3]))
idleCPU.append(float(repLine.split()[5]))
continue
if "avg-cpu:" in repLine:
# Set flag to 1
flag = 1
continue
if options.storage in repLine:
# Append each metric value to the proper array
rRqMerge.append(float(repLine.split()[1]))
wRqMerge.append(float(repLine.split()[2]))
readThroughput.append(float(repLine.split()[5]))
writeThroughput.append(float(repLine.split()[6]))
avgRqSize.append(float(repLine.split()[7]))
avgQuSize.append(float(repLine.split()[8]))
util.append(float(repLine.split()[13]))
continue
#------------------------------------------------------------------------------
# CPU Utilization
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
# Prepare x-axis data
time = range(1, len(userCPU) + 1)
# Draw Plot
ax.fill_between(time, y1=userCPU, y2=0, label='User', alpha=0.5, color=config.B_color_cycle[0], linewidth=2)
ax.fill_between(time, y1=systemCPU, y2=0, label='System', alpha=0.5, color=config.B_color_cycle[3], linewidth=2)
ax.fill_between(time, y1=iowaitCPU, y2=0, label='IOwait', alpha=0.5, color=config.B_color_cycle[2], linewidth=2)
ax.fill_between(time, y1=idleCPU, y2=0, label='Idle', alpha=0.2, color=config.B_color_cycle[1], linewidth=2)
# Axis name and Title
ax.set_title('CPU Utilization', fontsize=config.fontsize)
ax.set(ylim=[0, 100])
plt.ylabel('% CPU Utilization \nby User tasks', ha="center", fontsize=config.fontsize)
plt.xlabel('Time (s)', fontsize=config.fontsize)
# Legend
plt.legend(loc='upper right')
# Lighten Borders
plt.gca().spines["top"].set_alpha(0)
plt.gca().spines["bottom"].set_alpha(.3)
plt.gca().spines["right"].set_alpha(0)
plt.gca().spines["left"].set_alpha(.3)
# Save figure
plt.savefig('%s/cpu.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# User CPU Utilization
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
time = range(1, len(userCPU) + 1)
p1 = plt.plot(time, userCPU, color=config.B_color_cycle[0], label='User', zorder=2)
# Axis name
plt.ylabel('% CPU Utilization \nby User tasks', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/user_cpu.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# System CPU Utilization
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
p1 = plt.plot(time, systemCPU, color=config.B_color_cycle[1], label='System', zorder=2)
# Axis name
plt.ylabel('% CPU Utilization \nby System tasks', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/sys_cpu.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# IOwait CPU
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
p1 = plt.plot(time, iowaitCPU, color=config.B_color_cycle[2], label='IOwait', zorder=2)
# Axis name
plt.ylabel('% IOwait CPU Percentage Time \nWaiting for IO requests', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/iow_cpu.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# Idle CPU
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
p1 = plt.plot(time, idleCPU, color=config.B_color_cycle[3], label='Idle', zorder=2)
# Axis name
plt.ylabel('% Idle CPU Percentage Time \nand no Waiting for IO requests', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/idle_cpu.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# Read Throughput Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
time = range(1, len(readThroughput) + 1)
p1 = plt.plot(time, readThroughput, color=config.B_color_cycle[4], label='Read', zorder=2)
# Axis name
plt.ylabel('Read Throughput (MB/s)', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/r_thrput.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# Write Throughput Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
p1 = plt.plot(time, writeThroughput, color=config.B_color_cycle[5], label='Write', zorder=2)
# Axis name
plt.ylabel('Write Throughput (MB/s)', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/wr_thrput.png' % options.outputPath, bbox_inches='tight', zorder=2)
#------------------------------------------------------------------------------
# Read + Write Throughput Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
ax.fill_between(time, y1=writeThroughput, y2=0, label='Write', alpha=0.7, color=config.B_color_cycle[0], linewidth=2)
ax.fill_between(time, y1=readThroughput, y2=0, label='Read', alpha=0.7, color=config.B_color_cycle[1], linewidth=2)
# Axis name
ax.set_title('Read and Write Throughput', fontsize=config.fontsize)
plt.ylabel('Throughput (MB/s)', ha="center", fontsize=config.fontsize)
plt.xlabel('Time (s)', fontsize=config.fontsize)
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/thrput.png' % options.outputPath, bbox_inches='tight', zorder=2)
#------------------------------------------------------------------------------
# Average Request Size Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
time = range(1, len(avgRqSize) + 1)
p1 = plt.plot(time, avgRqSize, color=config.B_color_cycle[6], label='Avg. Req. Size', zorder=2)
# Axis name
plt.ylabel('Average Size of IO requests \n(sectors)', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/avg_rq_sz.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# Average Queue Size Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
time = range(1, len(avgRqSize) + 1)
p1 = plt.plot(time, avgQuSize, color=config.B_color_cycle[6], label='Avg. Queue. Size', zorder=2)
# Axis name
plt.ylabel('Average Queue Length of IO requests \n(sectors)', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/avg_qu_sz.png' % options.outputPath, bbox_inches='tight')
#------------------------------------------------------------------------------
# Utilization of Storage Device
#------------------------------------------------------------------------------
# Plot figure with fix size
fig, ax = plt.subplots(figsize=config.fullfigsize)
# Grid
plt.grid(True, linestyle='--', color='grey', zorder=0)
time = range(1, len(util) + 1)
p1 = plt.plot(time, util, color=config.B_color_cycle[7], label='Util', zorder=2)
# Axis name
plt.ylabel('% of CPU time for IO Requests', ha="center")
plt.xlabel('Time (s)')
# Legend
plt.legend(loc='upper right')
# Save figure
plt.savefig('%s/util.png' % options.outputPath, bbox_inches='tight')