From 40ff005a09d2d9f5ad3e0721119e39adf8c24467 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 26 Dec 2023 12:43:31 -0500 Subject: [PATCH] Fix handling of Ceph OSD bytes --- daemon-common/ceph.py | 12 ++++++------ daemon-common/cluster.py | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/daemon-common/ceph.py b/daemon-common/ceph.py index d4d906c6..2ef072a2 100644 --- a/daemon-common/ceph.py +++ b/daemon-common/ceph.py @@ -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) diff --git a/daemon-common/cluster.py b/daemon-common/cluster.py index 3855b012..224d6eef 100644 --- a/daemon-common/cluster.py +++ b/daemon-common/cluster.py @@ -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(