Open dirkmoors opened 6 years ago
My guess is that these checks have not been tested on Alpine Linux at all.
First of all, I would rewrite
to_float = lambda s: float(s.replace(",", "."))
to something like this:
def to_float(s):
FLOAT = re.compile(r'[0-9]+\.[0-9]+')
matches = FLOAT.findall(s)
if not matches:
return -1.0
return float(matches[0])
This is needed because the current "get_subprocess_output" will append strange byte-chars to the values, like '�'.
Secondly, I would update the "IO._parse_linux2" function to something like this:
class IO(Check):
...
def _parse_linux2(self, output):
TABLE_RE = re.compile(r'([a-zA-Z0-9([a-zA-Z0-9\%\/\._-]+)')
iostats = {}
header = []
lines = output.split('\n')
for i, line in enumerate(lines):
if line.startswith('Device'):
header = TABLE_RE.findall(lines[i])
assert header[0] == 'Device'
elif line.strip() == '':
header = []
continue
values = TABLE_RE.findall(lines[i + 1])
if values and len(values) == len(header):
device = values[0]
iostats[device] = {}
for i, key in enumerate(header[1:]):
iostats[device][key] = float(values[i + 1])
return iostats
...
This will parse the table more robustly imho.
This approach is still not providing all required statistics, but it might help in the right direction.
Bottom line: please add better support for Alpine Linux :)
any update on the reported issue?