From 0d5e81e794037ddbec0d279edf530b40de460565 Mon Sep 17 00:00:00 2001 From: niemijoe Date: Fri, 19 Aug 2022 14:55:58 +0300 Subject: [PATCH] Rounding fixes --- mqtt_data_collector.py | 6 +++++- pulsar_data_collector.py | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mqtt_data_collector.py b/mqtt_data_collector.py index 5a79bd1..eb68d56 100644 --- a/mqtt_data_collector.py +++ b/mqtt_data_collector.py @@ -157,9 +157,13 @@ def get_series_array(topic_data_collection): for key in topic_data_collection: topic_msg_count = topic_data_collection[key] - # We want message count to be message per second + # We want message count to be messages per second topic_msg_count = round(topic_msg_count/MONITOR_PERIOD_IN_SECONDS, 2) + # If over 10, round to whole number + if topic_msg_count > 10: + topic_msg_count = round(topic_msg_count) + # Azure doesn't seem to like # in a dimValue, replace it with * parsed_key = key.replace("#", "*") # Azure doesn't seem to like + in a dimValue, replace it with ^ diff --git a/pulsar_data_collector.py b/pulsar_data_collector.py index 22cf989..a375232 100644 --- a/pulsar_data_collector.py +++ b/pulsar_data_collector.py @@ -126,16 +126,18 @@ def get_series_array(topic_data_collection, topic_data_metric_name, topic_names_ series_array = [] for topic_name in topic_names_to_collect: topic_msg_count = topic_data_collection[topic_name][topic_data_metric_name] - # Special case: we want to multiply stop-cancellation messages by 10 - # so that the data would show more likely in Azure's charts - if topic_name == "internal-messages/stop-cancellation": - topic_msg_count = topic_msg_count * 10 + + topic_msg_count = round(topic_msg_count, 2) + + # If over 10, round to whole number + if topic_msg_count > 10: + topic_msg_count = round(topic_msg_count) dimValue = { "dimValues": [ topic_name ], - "sum": round(topic_msg_count), + "sum": topic_msg_count, "count": 1 } series_array.append(dimValue)