-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscaleio.py
413 lines (348 loc) · 15.9 KB
/
scaleio.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/usr/bin/python
__maintainer__ = "Abel Laura"
__email__ = "[email protected]"
import subprocess
import traceback
import types
import re
import json
import shlex
import getopt,sys
#If this is an AMS system, IP1 should be the AMS address.
MDMS = {
'MDM_IP1': '1.1.1.1',
'MDM_IP2': '1.1.1.2',
'MDM_IP3': '1.1.1.3'
}
CONF = {
'debug': False, #Debug
'verbose': False, #Extra info (needs to be rewriten or removed)
'scli_user': 'admin', #User to connect to the cluster
'scli_password': 'admin', #Password for the cluster
'mdm_ip': '1.1.1.1', #IP for the cluster
'pools': [], #Used with 'ignoreselected'
'scli_cmd': '/opt/clinicit/scli', #name of the binary scli. Should be accessible by path.
'ignoreselected': False, #Ignores pools listedn in 'pools'
'metric_label': 'vxflex_', #All Metrics will have this string prepended to the output.
}
POOLS_CAP = (
'NAME,MAX_CAPACITY_IN_KB,SPARE_CAPACITY_IN_KB,THIN_CAPACITY_ALLOCATED_IN_KB,'
'THICK_CAPACITY_IN_USE_IN_KB,UNUSED_CAPACITY_IN_KB,SNAP_CAPACITY_IN_USE_OCCUPIED_IN_KB,'
'CAPACITY_IN_USE_IN_KB,UNREACHABLE_UNUSED_CAPACITY_IN_KB,DEGRADED_HEALTHY_CAPACITY_IN_KB,'
'FAILED_CAPACITY_IN_KB,AVAILABLE_FOR_THICK_ALLOCATION_IN_KB,'
)
POOLS_PERF = (
'NAME,USER_DATA_READ_BWC,USER_DATA_WRITE_BWC,REBALANCE_READ_BWC,FWD_REBUILD_READ_BWC,BCK_REBUILD_READ_BWC,'
)
VOLUMES_CAP = (
'ID,NAME,SIZE,'
)
VOLUMES_PERF = (
'ID,NAME,USER_DATA_READ_BWC,USER_DATA_WRITE_BWC,'
)
SDSS_CAP = (
'ID,NAME,MAX_CAPACITY_IN_KB,MAX_CAPACITY_IN_KB,NUM_OF_DEVICES'
)
SDSS_PERF = (
'ID,NAME,TOTAL_READ_BWC,TOTAL_WRITE_BWC,'
)
SDCS_PERF = (
'ID,NAME,USER_DATA_READ_BWC,USER_DATA_WRITE_BWC,'
)
SDCS_CAP = (
'ID,NAME,IP,NUM_OF_MAPPED_VOLUMES,OS_TYPE,'
)
DEVICE_HEALTH = (
'SDS_ID,NAME,STATE,ERR_STATE,'
)
class AutoVivification(dict):
"""Implementation of perl's autovivification feature."""
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
def check_output(cmd):
try:
out=subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = out.communicate()[0]
except Exception as e:
print('Error on executing command: %s --- %s' %(e, traceback.format_exc()))
exit(1)
return output
def sclio_try_login(mdm_ip):
login_cmd = (CONF['scli_cmd'] + " --login --tech --username=" + CONF['scli_user'] + " --password='" + CONF['scli_password'] + "' --mdm_ip=" + mdm_ip)
my_debug(login_cmd)
out = check_output(shlex.split(login_cmd))
my_debug(out)
if 'Logged in' in out:
CONF['mdm_ip']=mdm_ip
return 1
else:
return 0
def sclio_login():
if (sclio_try_login(MDMS['MDM_IP1'])==1):
return 1
else:
if (sclio_try_login(MDMS['MDM_IP2'])==1):
return 1
else:
if (sclio_try_login(MDMS['MDM_IP3'])==1):
return 1
else:
return 0
def sclio_logout():
logout_cmd = (CONF['scli_cmd'] + " --tech --logout --mdm_ip=" + CONF['mdm_ip'])
out = check_output(shlex.split(logout_cmd))
my_debug(out)
def dispatch_value(plugin, value, plugin_instance=None, type_instance=None):
print('%s,%s=%s %s=%s' % (CONF['metric_label'] + plugin, plugin, plugin_instance, type_instance, value))
#Example output example,tag1=a,tag2=b i=42i,j=43i,k=44i
def dispatch_value_ex(label, label_val, tag1, tag1_val, i=None, i_val=None):
print('%s,%s=%s,%s=%s %s=%s' % (CONF['metric_label'] + label, label, label_val,tag1 ,tag1_val, i, i_val ))
def get_sdc(opt_params):
if opt_params == 1 :
sdcs = read_properties('--query_properties', '--object_type', 'SDC', '--all_objects',
'--properties', SDCS_PERF)
elif opt_params == 2 :
sdcs = read_properties('--query_properties', '--object_type', 'SDC', '--all_objects',
'--properties', SDCS_CAP)
else :
sdcs = read_properties('--query_properties', '--object_type', 'SDC', '--all_objects',
'--properties', SDCS_PERF+SDCS_CAP)
if sdcs == None:
return
for sdc_id, sdc in sdcs.iteritems():
if opt_params!=1 : dispatch_value('sdc', long(sdc['NUM_OF_MAPPED_VOLUMES']), sdc['NAME'], 'NUM_OF_MAPPED_VOLUMES')
if opt_params!=2 : dispatch_value('sdc', long(sdc['USER_DATA_READ_BWC']['IOPS']), sdc['NAME'], 'USER_DATA_READ_BWC_IOPS')
if opt_params!=2 : dispatch_value('sdc', long(sdc['USER_DATA_WRITE_BWC']['IOPS']), sdc['NAME'], 'USER_DATA_WRITE_BWC_IOPS')
if opt_params!=2 : dispatch_value('sdc', long(sdc['USER_DATA_READ_BWC']['BPS']), sdc['NAME'], 'USER_DATA_READ_BWC_BPS')
if opt_params!=2 : dispatch_value('sdc', long(sdc['USER_DATA_WRITE_BWC']['BPS']), sdc['NAME'], 'USER_DATA_WRITE_BWC_BPS')
def get_sds(opt_params):
if opt_params == 1 :
sdss = read_properties('--query_properties', '--object_type', 'SDS', '--all_objects',
'--properties', SDSS_PERF)
elif opt_params == 2 :
sdss = read_properties('--query_properties', '--object_type', 'SDS', '--all_objects',
'--properties', SDSS_CAP)
else :
sdss = read_properties('--query_properties', '--object_type', 'SDS', '--all_objects',
'--properties', SDSS_PERF+SDSS_CAP)
if sdss == None:
return
for sds_id, sds in sdss.iteritems():
if opt_params!=1 : dispatch_value('sds', long(sds['MAX_CAPACITY_IN_KB']) / 2, sds['NAME'], 'MAX_CAPACITY_IN_KB_RAW')
if opt_params!=1 : dispatch_value('sds', long(sds['NUM_OF_DEVICES']), sds['NAME'], 'NUM_OF_DEVICES')
if opt_params!=2 : dispatch_value('sds', long(sds['TOTAL_READ_BWC']['IOPS']), sds['NAME'], 'TOTAL_READ_BWC_IOPS')
if opt_params!=2 : dispatch_value('sds', long(sds['TOTAL_WRITE_BWC']['IOPS']), sds['NAME'], 'TOTAL_WRITE_BWC_IOPS')
if opt_params!=2 : dispatch_value('sds', long(sds['TOTAL_READ_BWC']['BPS']), sds['NAME'], 'TOTAL_READ_BWC_BPS')
if opt_params!=2 : dispatch_value('sds', long(sds['TOTAL_WRITE_BWC']['BPS']), sds['NAME'], 'TOTAL_WRITE_BWC_BPS')
def get_volumes(opt_params):
if opt_params == 1 :
volumes = read_properties('--query_properties', '--object_type', 'VOLUME', '--all_objects',
'--properties', VOLUMES_PERF)
elif opt_params == 2 :
volumes = read_properties('--query_properties', '--object_type', 'VOLUME', '--all_objects',
'--properties', VOLUMES_CAP)
else :
volumes = read_properties('--query_properties', '--object_type', 'VOLUME', '--all_objects',
'--properties', VOLUMES_CAP + VOLUMES_PERF)
if volumes == None:
return
for volume_id, volume in volumes.iteritems():
if opt_params!=1 : dispatch_value('volume', long(volume['SIZE']), volume['NAME'], 'SIZE')
if opt_params!=2 : dispatch_value('volume', long(volume['USER_DATA_READ_BWC']['IOPS']), volume['NAME'], 'USER_DATA_READ_BWC_IOPS')
if opt_params!=2 : dispatch_value('volume', long(volume['USER_DATA_WRITE_BWC']['IOPS']), volume['NAME'], 'USER_DATA_WRITE_BWC_IOPS')
if opt_params!=2 : dispatch_value('volume', long(volume['USER_DATA_READ_BWC']['BPS']), volume['NAME'], 'USER_DATA_READ_BWC_BPS')
if opt_params!=2 : dispatch_value('volume', long(volume['USER_DATA_WRITE_BWC']['BPS']), volume['NAME'], 'USER_DATA_WRITE_BWC_BPS')
def get_disks(opt_params):
if opt_params == 3 :
disks = read_properties('--query_properties','--object_type','DEVICE', '--all_objects',
'--properties', DEVICE_HEALTH)
if disks == None:
return
sdss = read_properties('--query_properties', '--object_type', 'SDS', '--all_objects',
'--properties', 'NAME')
if sdss == None:
return
for disk_id, disk in disks.iteritems():
dispatch_value_ex('disk',disk['NAME'],'sds',sdss[disk['SDS_ID']]['NAME'], 'failed',err2bool(disk['ERR_STATE']))
# Query ScaleIO for pool metrics.
def get_pools(opt_params):
if opt_params == 1 :
pools = read_properties('--query_properties', '--object_type', 'STORAGE_POOL', '--all_objects',
'--properties', POOLS_PERF)
elif opt_params == 2 :
pools = read_properties('--query_properties', '--object_type', 'STORAGE_POOL', '--all_objects',
'--properties', POOLS_CAP)
else :
pools = read_properties('--query_properties', '--object_type', 'STORAGE_POOL', '--all_objects',
'--properties', POOLS_CAP + POOLS_PERF)
# We have nothing to report
if pools == None:
return
for pool_id, pool in pools.iteritems():
# skip pools based on configuration
if len(CONF['pools']) > 0 and not CONF['ignoreselected'] and pool['NAME'] not in CONF['pools']:
my_verbose('Pool %s is not in pools configuration and ignoreselected is false -> skipping' % (pool['NAME']))
continue
if len(CONF['pools']) > 0 and CONF['ignoreselected'] and pool['NAME'] in CONF['pools']:
my_verbose('Pool %s is in pools configuration and ignoreselected is true -> skipping' % (pool['NAME']))
continue
# raw capacity
if opt_params!=1 : dispatch_value('pool', long(pool['MAX_CAPACITY_IN_KB']) / 2, pool['NAME'], 'MAX_CAPACITY_IN_KB_RAW')
# useable capacity
if opt_params!=1 : dispatch_value('pool',
long(pool['AVAILABLE_FOR_THICK_ALLOCATION_IN_KB']) + long(pool['CAPACITY_IN_USE_IN_KB']) / 2,
pool['NAME'], 'USABLE_CAPACITY_IN_KB')
# available capacity
if opt_params!=1 : dispatch_value('pool',
long(pool['AVAILABLE_FOR_THICK_ALLOCATION_IN_KB']),
pool['NAME'], 'AVAILABLE_FOR_ALLOCATION_IN_KB')
# used capacity
if opt_params!=1 : dispatch_value('pool', (long(pool['CAPACITY_IN_USE_IN_KB'])) / 2, pool['NAME'], 'CAPACITY_IN_USE_IN_KB')
# allocated capacity
if opt_params!=1 : dispatch_value('pool',
(long(pool['THIN_CAPACITY_ALLOCATED_IN_KB']) +
long(pool['THICK_CAPACITY_IN_USE_IN_KB']) + long(pool['SNAP_CAPACITY_IN_USE_OCCUPIED_IN_KB'])) / 2,
pool['NAME'], 'ALLOCATED_CAPACITY_IN_KB')
# unreachable unused capacity
if opt_params!=1 : dispatch_value('pool', long(pool['UNREACHABLE_UNUSED_CAPACITY_IN_KB']) / 2, pool['NAME'], 'UNREACHABLE_UNUSED_CAPACITY_IN_KB')
# degraded capacity
if opt_params!=1 : dispatch_value('pool', long(pool['DEGRADED_HEALTHY_CAPACITY_IN_KB']), pool['NAME'], 'DEGRADED_HEALTHY_CAPACITY_IN_KB')
# failed capacity
if opt_params!=1 : dispatch_value('pool', long(pool['FAILED_CAPACITY_IN_KB']) / 2, pool['NAME'], 'FAILED_CAPACITY_IN_KB')
# spare capacity
if opt_params!=1 : dispatch_value('pool', long(pool['SPARE_CAPACITY_IN_KB']), pool['NAME'], 'SPARE_CAPACITY_IN_KB')
# user data read IOPS
if opt_params!=2 : dispatch_value('pool', long(pool['USER_DATA_READ_BWC']['IOPS']), pool['NAME'], 'USER_DATA_READ_BWC_IOPS')
# user data read throughput
if opt_params!=2 : dispatch_value('pool', long(pool['USER_DATA_READ_BWC']['BPS']), pool['NAME'], 'USER_DATA_READ_BWC_BPS')
# user data write IOPS
if opt_params!=2 : dispatch_value('pool', long(pool['USER_DATA_WRITE_BWC']['IOPS']), pool['NAME'], 'USER_DATA_WRITE_BWC_IOPS')
# user data write throughput
if opt_params!=2 : dispatch_value('pool', long(pool['USER_DATA_WRITE_BWC']['BPS']), pool['NAME'], 'USER_DATA_WRITE_BWC_BPS')
# rebalance IOPS
if opt_params!=2 : dispatch_value('pool', long(pool['REBALANCE_READ_BWC']['IOPS']), pool['NAME'], 'REBALANCE_READ_BWC_IOPS')
# rebalance throughput
if opt_params!=2 : dispatch_value('pool', long(pool['REBALANCE_READ_BWC']['BPS']), pool['NAME'], 'REBALANCE_READ_BWC_BPS')
# rebuild IOPS
if opt_params!=2 : dispatch_value('pool',
long(pool['FWD_REBUILD_READ_BWC']['IOPS']) +
long(pool['BCK_REBUILD_READ_BWC']['IOPS']),
pool['NAME'], 'REBUILD_IOPS')
# rebuild throughput
if opt_params!=2 : dispatch_value('pool',
long(pool['FWD_REBUILD_READ_BWC']['BPS']) +
long(pool['BCK_REBUILD_READ_BWC']['BPS']),
pool['NAME'], 'REBUILD_BPS')
# Execute a scli --query_properties command and convert the CLI output to a dict/JSON
def read_properties(*cmd):
properties = AutoVivification()
out = None
real_cmd = (CONF['scli_cmd'],'--mdm_ip='+CONF['mdm_ip'], '--tech') + cmd
my_debug('Executing command: %s ' % (" ".join(str(v) for v in real_cmd)))
out = check_output(real_cmd)
if 'Failed to connect to MDM' in out:
my_verbose('Failed to connect to MDM, skipping data collection')
group_name = None
group_regex = re.compile("^([^\s]+)\s([^:]+)")
kv_regex = re.compile("^\s+([^\s]+)\s+(.*)$")
for line in out.split('\n'):
new_group_match = group_regex.match(line)
if new_group_match:
group_name = new_group_match.group(2)
else:
kv_match = kv_regex.match(line)
if kv_match:
properties[group_name][kv_match.group(1)] = kv_match.group(2)
my_verbose('Read properties: %s' % (json.dumps(properties)))
rectify_dict(properties)
my_debug('Properties after rectify: %s' % (json.dumps(properties)))
return properties
# Recitify the properties read from the command line:
# - convert units such as KB,MB,GB to bytes
# - interpret the BWC values and extract IOPS, Throughput
def rectify_dict(var):
for key, val in var.iteritems():
if type(val) is dict or type(val) is AutoVivification:
rectify_dict(val)
elif type(val) is str:
if key.endswith('BWC'):
var[key] = convert_bwc_to_dict(val)
else:
var[key] = convert_units_to_bytes(val)
def convert_bwc_to_dict(val):
m = re.search('([0-9]+) IOPS (.*) per-second', val, re.I)
return {'IOPS': m.group(1), 'BPS': convert_units_to_bytes(m.group(2))}
def convert_units_to_bytes(val):
val = convert_unit_to_bytes(val, "Bytes", 0)
val = convert_unit_to_bytes(val, "KB", 1)
val = convert_unit_to_bytes(val, "MB", 2)
val = convert_unit_to_bytes(val, "GB", 3)
val = convert_unit_to_bytes(val, "TB", 4)
val = convert_unit_to_bytes(val, "PB", 5)
return val
def convert_unit_to_bytes(val, unit, power):
m = re.search('([0-9\.]+) ' + unit, val, re.I)
if m:
return str(long(m.group(1)) * (1024 ** power))
return val
def str2bool(v):
if type(v) == types.BooleanType:
return v
return v.lower() in ("yes", "true", "t", "1")
def err2bool(v):
if type(v) == types.BooleanType:
return v
return int(v.lower() in ("error"))
def my_debug(msg):
if CONF['debug']:
print('ScaleIO: %s' % (msg))
def my_verbose(msg):
if CONF['verbose']:
print('ScaleIO: %s' % (msg))
def main(argv):
if len(sys.argv) == 1:
exit()
try:
opts, args = getopt.getopt(sys.argv[1:],"pcha")
except getopt.GetoptError as err:
print err
sys.exit(2)
capacity=False
performance=False
health=False
params=0
for o, a in opts:
if o == "-p":
performance = True
params=1
elif o in ("-c"):
capacity = True
params=2
elif o in ("-h"):
health = True
params=3
elif o in ("-a"):
capacity = True
performance = True
health = True
params=4
else:
assert False, "Nothing to do"
exit()
if (sclio_login()==1):
if params == 3:
get_disks(params)
else:
get_pools(params)
get_volumes(params)
get_sds(params)
get_sdc(params)
sclio_logout()
else:
print('Error: Login failed')
if __name__ == "__main__":
main(sys.argv[1:])