Merge pull request #40525 from dmurphy18/aix_dskiostat

Add support for disk.iostat on AIX
This commit is contained in:
Mike Place 2017-04-04 13:31:41 -06:00 committed by GitHub
commit 0dd92c63ea

View File

@ -37,6 +37,27 @@ def __virtual__():
return True
def _parse_numbers(text):
'''
Convert a string to a number, allowing for a K|M|G|T postfix, 32.8K.
Returns a decimal number if the string is a real number,
or the string unchanged otherwise.
'''
if text.isdigit():
return decimal.Decimal(text)
try:
postPrefixes = {'K': '10E3', 'M': '10E6', 'G': '10E9', 'T': '10E12', 'P': '10E15', 'E': '10E18', 'Z': '10E21', 'Y': '10E24'}
if text[-1] in postPrefixes.keys():
v = decimal.Decimal(text[:-1])
v = v * decimal.Decimal(postPrefixes[text[-1]])
return v
else:
return decimal.Decimal(text)
except ValueError:
return text
def _clean_flags(args, caller):
'''
Sanitize flags passed into df
@ -723,6 +744,9 @@ def iostat(interval=1, count=5, disks=None):
.. versionadded:: 2016.3.0
.. versionchanged:: 2016.11.4
Added support for AIX
CLI Example:
.. code-block:: bash
@ -733,6 +757,8 @@ def iostat(interval=1, count=5, disks=None):
return _iostat_linux(interval, count, disks)
elif salt.utils.is_freebsd():
return _iostat_fbsd(interval, count, disks)
elif salt.utils.is_aix():
return _iostat_aix(interval, count, disks)
def _iostats_dict(header, stats):
@ -843,3 +869,103 @@ def _iostat_linux(interval, count, disks):
iostats[disk] = _iostats_dict(dev_header, stats)
return iostats
def _iostat_aix(interval, count, disks):
'''
AIX support to gather and return (averaged) IO stats.
'''
log.debug('DGM disk iostat entry')
if disks is None:
iostat_cmd = 'iostat -dD {0} {1} '.format(interval, count)
elif isinstance(disks, six.string_types):
iostat_cmd = 'iostat -dD {0} {1} {2}'.format(disks, interval, count)
else:
iostat_cmd = 'iostat -dD {0} {1} {2}'.format(' '.join(disks), interval, count)
ret = {}
procn = None
fields = []
disk_name = ''
disk_mode = ''
dev_stats = collections.defaultdict(list)
for line in __salt__['cmd.run'](iostat_cmd).splitlines():
# Note: iostat -dD is per-system
#
#root@l490vp031_pub:~/devtest# iostat -dD hdisk6 1 3
#
#System configuration: lcpu=8 drives=1 paths=2 vdisks=2
#
#hdisk6 xfer: %tm_act bps tps bread bwrtn
# 0.0 0.0 0.0 0.0 0.0
# read: rps avgserv minserv maxserv timeouts fails
# 0.0 0.0 0.0 0.0 0 0
# write: wps avgserv minserv maxserv timeouts fails
# 0.0 0.0 0.0 0.0 0 0
# queue: avgtime mintime maxtime avgwqsz avgsqsz sqfull
# 0.0 0.0 0.0 0.0 0.0 0.0
#--------------------------------------------------------------------------------
#
#hdisk6 xfer: %tm_act bps tps bread bwrtn
# 9.6 16.4K 4.0 16.4K 0.0
# read: rps avgserv minserv maxserv timeouts fails
# 4.0 4.9 0.3 9.9 0 0
# write: wps avgserv minserv maxserv timeouts fails
# 0.0 0.0 0.0 0.0 0 0
# queue: avgtime mintime maxtime avgwqsz avgsqsz sqfull
# 0.0 0.0 0.0 0.0 0.0 0.0
#--------------------------------------------------------------------------------
#
#hdisk6 xfer: %tm_act bps tps bread bwrtn
# 0.0 0.0 0.0 0.0 0.0
# read: rps avgserv minserv maxserv timeouts fails
# 0.0 0.0 0.3 9.9 0 0
# write: wps avgserv minserv maxserv timeouts fails
# 0.0 0.0 0.0 0.0 0 0
# queue: avgtime mintime maxtime avgwqsz avgsqsz sqfull
# 0.0 0.0 0.0 0.0 0.0 0.0
#--------------------------------------------------------------------------------
if not line or line.startswith('System') or line.startswith('-----------'):
continue
if not re.match(r'\s', line):
#seen disk name
dsk_comps = line.split(':')
dsk_firsts = dsk_comps[0].split()
disk_name = dsk_firsts[0]
disk_mode = dsk_firsts[1]
fields = dsk_comps[1].split()
if disk_name not in dev_stats.keys():
dev_stats[disk_name] = []
procn = len(dev_stats[disk_name])
dev_stats[disk_name].append({})
dev_stats[disk_name][procn][disk_mode] = {}
dev_stats[disk_name][procn][disk_mode]['fields'] = fields
dev_stats[disk_name][procn][disk_mode]['stats'] = []
continue
if ':' in line:
comps = line.split(':')
fields = comps[1].split()
disk_mode = comps[0].lstrip()
if disk_mode not in dev_stats[disk_name][0].keys():
dev_stats[disk_name][0][disk_mode] = {}
dev_stats[disk_name][0][disk_mode]['fields'] = fields
dev_stats[disk_name][0][disk_mode]['stats'] = []
else:
line = line.split()
stats = [_parse_numbers(x) for x in line[:]]
dev_stats[disk_name][0][disk_mode]['stats'].append(stats)
iostats = {}
for disk, list_modes in dev_stats.items():
iostats[disk] = {}
for modes in list_modes:
for disk_mode in modes.keys():
fields = modes[disk_mode]['fields']
stats = modes[disk_mode]['stats']
iostats[disk][disk_mode] = _iostats_dict(fields, stats)
return iostats