Fix handling of Ceph OSD bytes
This commit is contained in:
parent
ab4ec7a5fa
commit
40ff005a09
|
@ -123,13 +123,13 @@ def format_bytes_tohuman(databytes):
|
|||
def format_bytes_fromhuman(datahuman):
|
||||
if not re.search(r"[A-Za-z]+", datahuman):
|
||||
dataunit = "B"
|
||||
datasize = int(datahuman)
|
||||
datasize = float(datahuman)
|
||||
else:
|
||||
dataunit = str(re.match(r"[0-9]+([A-Za-z])[iBb]*", datahuman).group(1))
|
||||
datasize = int(re.match(r"([0-9]+)[A-Za-z]+", datahuman).group(1))
|
||||
dataunit = str(re.match(r"[0-9\.]+([A-Za-z])[iBb]*", datahuman).group(1))
|
||||
datasize = float(re.match(r"([0-9\.]+)[A-Za-z]+", datahuman).group(1))
|
||||
|
||||
if byte_unit_matrix.get(dataunit):
|
||||
databytes = datasize * byte_unit_matrix[dataunit]
|
||||
if byte_unit_matrix.get(dataunit.upper()):
|
||||
databytes = int(datasize * byte_unit_matrix[dataunit.upper()])
|
||||
return databytes
|
||||
else:
|
||||
return None
|
||||
|
@ -155,7 +155,7 @@ def format_ops_fromhuman(datahuman):
|
|||
# Trim off human-readable character
|
||||
dataunit = datahuman[-1]
|
||||
datasize = int(datahuman[:-1])
|
||||
dataops = datasize * ops_unit_matrix[dataunit]
|
||||
dataops = datasize * ops_unit_matrix[dataunit.upper()]
|
||||
return "{}".format(dataops)
|
||||
|
||||
|
||||
|
|
|
@ -1496,11 +1496,11 @@ def get_resource_metrics(zkhandler):
|
|||
continue
|
||||
output_lines.append(f"pvc_ceph_osd_wr_ops{{osd=\"{osd['id']}\"}} {osd_wr_ops}")
|
||||
|
||||
output_lines.append("# HELP pvc_ceph_osd_wr_data PVC OSD write KB per second")
|
||||
output_lines.append("# HELP pvc_ceph_osd_wr_data PVC OSD write bytes per second")
|
||||
output_lines.append("# TYPE pvc_ceph_osd_wr_data gauge")
|
||||
for osd in osd_data:
|
||||
try:
|
||||
osd_wr_data = osd["stats"]["wr_data"]
|
||||
osd_wr_data = pvc_ceph.format_bytes_fromhuman(osd["stats"]["wr_data"])
|
||||
except Exception:
|
||||
continue
|
||||
output_lines.append(
|
||||
|
@ -1516,11 +1516,11 @@ def get_resource_metrics(zkhandler):
|
|||
continue
|
||||
output_lines.append(f"pvc_ceph_osd_rd_ops{{osd=\"{osd['id']}\"}} {osd_rd_ops}")
|
||||
|
||||
output_lines.append("# HELP pvc_ceph_osd_rd_data PVC OSD read KB per second")
|
||||
output_lines.append("# HELP pvc_ceph_osd_rd_data PVC OSD read bytes per second")
|
||||
output_lines.append("# TYPE pvc_ceph_osd_rd_data gauge")
|
||||
for osd in osd_data:
|
||||
try:
|
||||
osd_rd_data = osd["stats"]["rd_data"]
|
||||
osd_rd_data = pvc_ceph.format_bytes_fromhuman(osd["stats"]["rd_data"])
|
||||
except Exception:
|
||||
continue
|
||||
output_lines.append(
|
||||
|
|
Loading…
Reference in New Issue