Skip to content

Commit

Permalink
cap values to 102%
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristineTChen committed Apr 27, 2018
1 parent 5d334d7 commit 8ea810f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions checks/system/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def __init__(self, logger):
self.item_re = re.compile(r'^([\-a-zA-Z0-9\/]+)')
self.value_re = re.compile(r'\d+\.\d+')

def _cap_io_util_value(self, val):
# Cap system.io.util metric value to 102%
# This is a known won't fix bug in iostat
if val > 102:
self.logger.exception("The %util value exceeds the limit: {}%".format(val))
return 0
else:
return val

def _parse_linux2(self, output):
recentStats = output.split('Device:')[2].split('\n')
header = recentStats[0]
Expand Down Expand Up @@ -72,6 +81,8 @@ def _parse_linux2(self, output):

for headerIndex in range(len(headerNames)):
headerName = headerNames[headerIndex]
if 'util' in headerName:
values[headerIndex] = self._cap_io_util_value(values[headerIndex])
ioStats[device][headerName] = values[headerIndex]

return ioStats
Expand Down Expand Up @@ -166,7 +177,10 @@ def check(self, agentConfig):
# cols[1:] are the values
io[cols[0]] = {}
for i in range(1, len(cols)):
io[cols[0]][self.xlate(headers[i], "sunos")] = cols[i]
xlate_header = self.xlate(headers[i], "sunos")
if 'util' in xlate_header:
cols[i] = self._cap_io_util_value(cols[i])
io[cols[0]][xlate_header] = cols[i]

elif sys.platform.startswith("freebsd"):
output, _, _ = get_subprocess_output(["iostat", "-x", "-d", "1", "2"], self.logger)
Expand Down Expand Up @@ -194,7 +208,10 @@ def check(self, agentConfig):
# cols[1:] are the values
io[cols[0]] = {}
for i in range(1, len(cols)):
io[cols[0]][self.xlate(headers[i], "freebsd")] = cols[i]
xlate_header = self.xlate(headers[i], "freebsd")
if 'utils' in xlate_header:
cols[i] = self._cap_io_util_value(cols[i])
io[cols[0]][xlate_header] = cols[i]
elif sys.platform == 'darwin':
iostat, _, _ = get_subprocess_output(['iostat', '-d', '-c', '2', '-w', '1'], self.logger)
# disk0 disk1 <-- number of disks
Expand Down

0 comments on commit 8ea810f

Please sign in to comment.