-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_collect.py
380 lines (313 loc) · 9.96 KB
/
stats_collect.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import time
import sys
sys.path.append("/u/ppradeepkumar/MyPython/Python-2.7.6/")
import pexpect
import re
import json
perl_wrap= 'nohup perl -e \'$i=5;while ($i) {system (\"%s%s%s%s\");$i--;sleep 1}\'&'
loadgen_cmd="/var/loadgen_edge.dbg -f "
loadgen_cfg=" /var/cfg/loadgen-{:d}.xml "
loadgen_args=" --test-duration 1500 --read-op --lba-cnt 97656250 --burst-rate 65536 --num-ops 2,100 > "
loadgen_logs=" logx/{:d}.txt 2>&1 "
class file_op():
handle=None
def __init__(self):
self.handle= open('stats_collect.512k','w',0)
def write_data(self,data):
for d in data:
self.handle.write("%s\n" % d)
class metrics():
data=None
def conv_bytes_to_kb(self):
return self.data/1000
def conv_mb_to_kb(self):
return self.data*1000
def conv_gb_to_kb(self):
return self.data*1000000
class stats_proc(file_op):
rx1= re.compile('Total (data|bytes) read\s*:\s*(\S+)\s*(\S+)',re.IGNORECASE)
rx3= re.compile('Avg Read IO Time\s*:\s*(\S+)\s*(\S+)',re.IGNORECASE)
delay=180
def read_stat(self,data):
for i in data:
rx2= self.rx1.search(i)
if rx2:
m= metrics()
m.data= float(rx2.group(2))
if re.search(rx2.group(3),'MB',re.IGNORECASE):
return m.conv_mb_to_kb()/self.delay
if re.search(rx2.group(3),'GB',re.IGNORECASE):
return m.conv_gb_to_kb()/self.delay
if re.search(rx2.group(3),'Bytes',re.IGNORECASE):
return m.conv_bytes_to_kb()/self.delay
def read_latency(self,data):
for i in data:
rx4= self.rx3.search(i)
if rx4:
return rx4.group(1)+" "+ rx4.group(2)
class va_box_prompt(object):
COMMAND_PROMPT=None
CLI_PROMPT=None
CLI_PROMPT1=None
def __init__(self):
self.COMMAND_PROMPT= re.compile('\[admin\@\S+ \S+\]#')
self.CLI_PROMPT= re.compile('\S+\s*(>|#|\(config\)\s*#)')
self.CLI_PROMPT1= re.compile('\S+\s*\(config\)\s*#')
self.password= re.compile('password')
class va_box(va_box_prompt):
hostname=None
shell=None
cli=None
user='root'
def get_login(self):
login(self)
login(self,access='cli')
def exec_on_shell(self,cmd):
return exec_this_shell_cmd(self,cmd)
def exec_on_cli(self,cmd):
return exec_this_cli_cmd(self,cmd)
class win_box():
hostname=None
shell=None
user='Administrator'
COMMAND_PROMPT= re.compile('Administrator\@\S+\s+\S+')
password= re.compile('Administrator\@\S+\s+password')
def get_login(self):
login(self)
def start_dd(self):
exec_this_shell_cmd(self,'ls /cygdrive/d')
cmd= 'dd if=\'\\\\.\\PhysicalDrive3\' of=/dev/null bs=512k count=100000 &'
return exec_this_shell_cmd(self,cmd)
class loadgen_box(va_box):
instance=0
def get_login(self):
super(loadgen_box,self).get_login()
super(loadgen_box,self).exec_on_shell('cd /var')
def kill_loadgen(self):
super(loadgen_box,self).exec_on_shell('pkill perl; pkill loadgen')
def loadgen_rm_core(self):
super(loadgen_box,self).exec_on_shell('rm -f /var/core*')
def start_loadgen_cmd(self,count):
cfg= loadgen_cfg.format(count)
log= loadgen_logs.format(count)
self.exec_on_shell(perl_wrap%(loadgen_cmd,cfg,loadgen_args,log))
stor_stats= 'show stats storage '
stor_stats1= '{:s} start-time \'{:s}\' end-time \'{:s}\' {:s} '
class stats_collect():
start_time=None
end_time=None
def form_time(self):
self.start_time= self.start_time.replace('-','/')
self.end_time= self.end_time.replace('-','/')
def form_stats_cmd(self,appnd):
return stor_stats + stor_stats1.format(appnd[0],self.start_time,self.end_time,appnd[1])
cmd= 'ssh'
params= ''' -oStrictHostKeyChecking=no
-oCheckHostIP=no -oForwardX11=no
-oUserKnownHostsFile=/dev/null
-oConnectTimeout=10 -oServerAliveInterval=300
-oForwardAgent=no '''
#systems=[ probe, loadgen, tarpon ]
def login(self,access='shell'):
hostname= self.hostname
user= self.user + '\@'
cmd1 = cmd + params + user + hostname
child= pexpect.spawn(cmd1)
child.logfile = sys.stdout
# child.logfile = open('py_logfile','w',0)
index= child.expect([self.password,self.COMMAND_PROMPT,pexpect.EOF])
# import pdb; pdb.set_trace()
if index==0:
child.sendline( '2top90!')
child.expect(self.COMMAND_PROMPT)
self.shell= child
elif index!=1:
print "Not able to login"
sys.exit(0)
if access is 'shell':
self.shell= child
elif access is 'cli':
child.sendline('cli')
child.expect('>')
child.sendline('terminal length 0')
child.expect(self.CLI_PROMPT)
child.sendline('en')
child.expect(self.CLI_PROMPT)
child.sendline('con t')
child.expect(self.CLI_PROMPT1)
self.cli= child
def get_output_only(output):
out= output.split('\n')
#Except the first and last line, consider all other lines as ouput
# Take out first line
out.pop(0)
#take out last line
out.pop()
out1= map(str.strip,out)
return out1
def exec_this_cli_cmd(self,cmd,get_input=False):
if get_input:
cmd=raw_input("Enter the command to execute:")
self.cli.sendline(cmd)
self.cli.expect(self.CLI_PROMPT1,timeout=160)
output= self.cli.before
output1= get_output_only(output)
return output1
def exec_this_shell_cmd(self,cmd,get_input=False):
if get_input:
cmd=raw_input("Enter the command to execute:")
self.shell.sendline(cmd)
self.shell.expect(self.COMMAND_PROMPT,timeout=160)
output= self.shell.before
output1= get_output_only(output)
return output1
#import pdb; pdb.set_trace()
#Probe edge
probe= va_box()
probe.hostname='oak-sh610'
probe.get_login()
# Edge on which loadgen runs
loadgen= loadgen_box()
loadgen.hostname='oak-sh584'
loadgen.get_login()
# Tarpon core
tarpon= va_box()
tarpon.hostname='oak-sh809'
tarpon.get_login()
#import pdb; pdb.set_trace()
# Windows
win= win_box()
win.hostname='oak-cs226'
win.get_login()
f= file_op()
s= stats_proc()
def show_systems():
for i in handles.keys():
print i
def start_loadgen():
loadgen.instance+=1
end= 10 * loadgen.instance;
print " Starting {:d} loadgen instances ..".format(end)
f.write_data([" Starting {:d} loadgen instances ..".format(end)])
for i in range(1,end):
loadgen.start_loadgen_cmd(i)
# time.sleep(1)
def connected_edges():
count=0
while count < loadgen.instance*10:
count=0
tmp= tarpon.exec_on_cli("show edge")
rx= re.compile('connection duration\s*:\s*(\S+)',re.IGNORECASE)
# import pdb; pdb.set_trace()
for i in tmp:
rx2= rx.search(i)
if rx2:
if rx2.group(1) != '0s':
count+=1
print '... {:d} connected edges ...'.format(count)
f.write_data(['... {:d} connected edges ...'.format(count)])
time.sleep(15)
def clear_restart_edge():
probe.exec_on_cli("service storage restart clean")
def restart_core():
tarpon.exec_on_cli("service restart ")
def get_stats():
date_cmd= 'date +\'%F %T\''
core1= stats_collect()
edge1= stats_collect()
core_start_time= tarpon.exec_on_shell(date_cmd)
core1.start_time= core_start_time[0]
edge_start_time= probe.exec_on_shell(date_cmd)
edge1.start_time= edge_start_time[0]
time.sleep(s.delay)
core_end_time= tarpon.exec_on_shell(date_cmd)
core1.end_time= core_end_time[0]
edge_end_time= probe.exec_on_shell(date_cmd)
edge1.end_time= edge_end_time[0]
core1.form_time()
edge1.form_time()
tup=()
tup=('filer-bytes','filer all')
tarpon_stats= tarpon.exec_on_cli(core1.form_stats_cmd(tup))
f.write_data(tarpon_stats)
# ret= str(s.read_stat(tarpon_stats))+' KB'
# f.write_data([ret])
sep= " "*50
f.write_data([sep])
# import pdb; pdb.set_trace()
tup=()
tup=('filer-latency','filer all')
tarpon_stats= tarpon.exec_on_cli(core1.form_stats_cmd(tup))
f.write_data(tarpon_stats)
# ret= s.read_latency(tarpon_stats)
# f.write_data([ret])
sep= " "*50
f.write_data([sep])
tup=()
tup=('lun-bytes','lun all')
probe_stats= probe.exec_on_cli(edge1.form_stats_cmd(tup))
f.write_data(probe_stats)
# ret= str(s.read_stat(probe_stats))+' KB'
# f.write_data([ret])
sep= " "*50
f.write_data([sep])
tup=()
tup=('lun-latency','lun all')
probe_stats= probe.exec_on_cli(edge1.form_stats_cmd(tup))
f.write_data(probe_stats)
# ret= s.read_latency(probe_stats)
# f.write_data([ret])
# import pdb; pdb.set_trace()
sep= "-"*50
f.write_data([sep])
#import pdb; pdb.set_trace()
#loadgen.loadgen_rm_core()
#start_loadgen()
#connected_edges()
loadgen.kill_loadgen()
clear_restart_edge()
restart_core()
time.sleep(100)
win.start_dd()
time.sleep(3)
get_stats()
iter=15
while iter>0:
loadgen.kill_loadgen()
clear_restart_edge()
restart_core()
time.sleep(100)
loadgen.loadgen_rm_core()
start_loadgen()
connected_edges()
time.sleep(5)
win.start_dd()
time.sleep(20)
get_stats()
iter-=1
while 1:
print "\n\nselect options below\n"
print "\t\t10. Start 10 Loadgen instances\n"
print "\t\t20. Exit\n"
print "\t\t30. Collect stats\n"
print "\t\t31. Clean restart probe edge\n"
print "\t\t32. restart core\n"
print "\t\t33. kill loadgens\n"
print "\t\t34. show connected edges\n"
print "\t\t35. win start dd\n"
# import pdb; pdb.set_trace()
in1=raw_input("Enter here:")
print in1
if in1 == '':
continue
options = {
'10':start_loadgen,
'20':sys.exit,
'30':get_stats,
'31':clear_restart_edge,
'32':restart_core,
'33':loadgen.kill_loadgen,
'34':connected_edges,
'35':win.start_dd,
}
options[in1]()