diff --git a/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py b/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py index e1598f5..23fce67 100644 --- a/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py +++ b/aviso-server/monitoring/aviso_monitoring/reporter/opsview_reporter.py @@ -146,7 +146,7 @@ def aggregate_time_tlms(tlms): """ if len(tlms) == 0: return None - + logger.debug(f"tlms: {tlms}") # Initialize the aggregated telemetry @@ -156,7 +156,7 @@ def aggregate_time_tlms(tlms): for tlm in tlms: r_tlm = tlm.get("telemetry") for key in r_tlm.keys(): - tlm_type = key[:key.rfind("_")] + tlm_type = key[: key.rfind("_")] # Initialize if tlm_type is new if tlm_type not in agg_tlm: @@ -193,25 +193,28 @@ def aggregate_unique_counter_tlms(tlms): if len(tlms) == 0: return None - # read only the telemetry field of the tlm - r_tlms = list(map(lambda t: t.get("telemetry"), tlms)) + agg_tlms = {} - # determine tlm_type - first_key = list(r_tlms[0].keys())[0] - tlm_type = first_key[: first_key.rfind("_")] + for tlm in tlms: + telemetry_data = tlm.get("telemetry", {}) + for key, values in telemetry_data.items(): + if key.endswith("_values"): + tlm_type = key[: key.rfind("_")] - # create a unique list of values - aggr_values = [] - for tlm in r_tlms: - for v in tlm[tlm_type + "_values"]: - if v not in aggr_values: - aggr_values.append(v) + if tlm_type not in agg_tlms: + agg_tlms[tlm_type] = { + tlm_type + "_counter": 0, + tlm_type + "_values": set(), + } - agg_tlm = { - tlm_type + "_counter": len(aggr_values), - tlm_type + "_values": aggr_values, - } - return agg_tlm + agg_tlms[tlm_type][tlm_type + "_values"].update(values) + + # Convert sets to lists and update counters + for tlm_type, data in agg_tlms.items(): + data[tlm_type + "_values"] = list(data[tlm_type + "_values"]) + data[tlm_type + "_counter"] = len(data[tlm_type + "_values"]) + + return agg_tlms @classmethod def retrieve_metrics(cls, metric_servers, req_timeout):