From ba565ead4c3d89e5fa847776f3db23a29edc6b04 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 9 Dec 2023 12:38:23 -0500 Subject: [PATCH] Report all state combinations in Prom metrics Ensures that every state combination is always shown to metrics, even if it contains 0 entries. --- api-daemon/pvcapid/helper.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index 243ba82d..12b19006 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -189,21 +189,23 @@ def cluster_metrics(zkhandler): output_lines.append("# HELP pvc_nodes PVC node state counts") output_lines.append("# TYPE pvc_nodes gauge") - for state in status_data["nodes"]: + for state in pvc_common.node_state_combinations: output_lines.append( - f"pvc_nodes{{state=\"{state}\"}} {status_data['nodes'][state]}" + f"pvc_nodes{{state=\"{state}\"}} {status_data['nodes'].get(state, 0)}" ) output_lines.append("# HELP pvc_vms PVC VM state counts") output_lines.append("# TYPE pvc_vms gauge") - for state in status_data["vms"]: - output_lines.append(f"pvc_vms{{state=\"{state}\"}} {status_data['vms'][state]}") + for state in pvc_common.vm_state_combinations: + output_lines.append( + f"pvc_vms{{state=\"{state}\"}} {status_data['vms'].get(state, 0)}" + ) output_lines.append("# HELP pvc_osds PVC OSD state counts") output_lines.append("# TYPE pvc_osds gauge") - for state in status_data["osds"]: + for state in pvc_common.ceph_osd_state_combinations: output_lines.append( - f"pvc_osds{{state=\"{state}\"}} {status_data['osds'][state]}" + f"pvc_osds{{state=\"{state}\"}} {status_data['osds'].get(state, 0)}" ) output_lines.append("# HELP pvc_networks PVC network count")