Fix handling of Ceph OSD bytes

This commit is contained in:
Joshua Boniface 2023-12-26 12:43:31 -05:00
parent ab4ec7a5fa
commit 40ff005a09
2 changed files with 10 additions and 10 deletions

View File

@ -123,13 +123,13 @@ def format_bytes_tohuman(databytes):
def format_bytes_fromhuman(datahuman): def format_bytes_fromhuman(datahuman):
if not re.search(r"[A-Za-z]+", datahuman): if not re.search(r"[A-Za-z]+", datahuman):
dataunit = "B" dataunit = "B"
datasize = int(datahuman) datasize = float(datahuman)
else: else:
dataunit = str(re.match(r"[0-9]+([A-Za-z])[iBb]*", datahuman).group(1)) 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)) datasize = float(re.match(r"([0-9\.]+)[A-Za-z]+", datahuman).group(1))
if byte_unit_matrix.get(dataunit): if byte_unit_matrix.get(dataunit.upper()):
databytes = datasize * byte_unit_matrix[dataunit] databytes = int(datasize * byte_unit_matrix[dataunit.upper()])
return databytes return databytes
else: else:
return None return None
@ -155,7 +155,7 @@ def format_ops_fromhuman(datahuman):
# Trim off human-readable character # Trim off human-readable character
dataunit = datahuman[-1] dataunit = datahuman[-1]
datasize = int(datahuman[:-1]) datasize = int(datahuman[:-1])
dataops = datasize * ops_unit_matrix[dataunit] dataops = datasize * ops_unit_matrix[dataunit.upper()]
return "{}".format(dataops) return "{}".format(dataops)

View File

@ -1496,11 +1496,11 @@ def get_resource_metrics(zkhandler):
continue continue
output_lines.append(f"pvc_ceph_osd_wr_ops{{osd=\"{osd['id']}\"}} {osd_wr_ops}") 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") output_lines.append("# TYPE pvc_ceph_osd_wr_data gauge")
for osd in osd_data: for osd in osd_data:
try: try:
osd_wr_data = osd["stats"]["wr_data"] osd_wr_data = pvc_ceph.format_bytes_fromhuman(osd["stats"]["wr_data"])
except Exception: except Exception:
continue continue
output_lines.append( output_lines.append(
@ -1516,11 +1516,11 @@ def get_resource_metrics(zkhandler):
continue continue
output_lines.append(f"pvc_ceph_osd_rd_ops{{osd=\"{osd['id']}\"}} {osd_rd_ops}") 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") output_lines.append("# TYPE pvc_ceph_osd_rd_data gauge")
for osd in osd_data: for osd in osd_data:
try: try:
osd_rd_data = osd["stats"]["rd_data"] osd_rd_data = pvc_ceph.format_bytes_fromhuman(osd["stats"]["rd_data"])
except Exception: except Exception:
continue continue
output_lines.append( output_lines.append(