From 821056664e571c707094ed8fd4f1e617ec064232 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Fri, 26 Jul 2024 13:18:09 +0300 Subject: [PATCH] Removed metric on message size in char len and replaced with overall size of packet by common labels and portnum --- .env | 2 -- exporter/processor_base.py | 17 ++++++++++++++++- exporter/processors.py | 7 +------ exporter/registry.py | 11 +---------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.env b/.env index 91ef300..3f1ca5e 100644 --- a/.env +++ b/.env @@ -29,8 +29,6 @@ MQTT_CALLBACK_API_VERSION=VERSION2 MESH_HIDE_SOURCE_DATA=false ## Hide destination data in the exporter (default: false) MESH_HIDE_DESTINATION_DATA=false -## Hide message content in the TEXT_MESSAGE_APP packets (default: true) (Currently we only log message length, if we hide then all messages would have the same length) -HIDE_MESSAGE=false ## MQTT server Key for decoding MQTT_SERVER_KEY=1PG7OiApB1nwvP+rz05pAQ== diff --git a/exporter/processor_base.py b/exporter/processor_base.py index b66ba4b..80eaed8 100644 --- a/exporter/processor_base.py +++ b/exporter/processor_base.py @@ -1,5 +1,6 @@ import base64 import os +import sys from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes @@ -20,6 +21,7 @@ from exporter.processors import ProcessorRegistry class MessageProcessor: def __init__(self, registry: CollectorRegistry, db_pool: ConnectionPool): + self.message_size_in_bytes = None self.rx_rssi_gauge = None self.channel_counter = None self.packet_id_counter = None @@ -44,6 +46,13 @@ class MessageProcessor: 'destination_role' ] + self.message_size_in_bytes = Histogram( + 'text_message_app_size_in_bytes', + 'Size of text messages processed by the app in Bytes', + common_labels + ['portnum'], + registry=self.registry + ) + self.source_message_type_counter = Counter( 'mesh_packet_source_types', 'Types of mesh packets processed by source', @@ -181,7 +190,8 @@ class MessageProcessor: return enum_value.name return 'UNKNOWN_PORT' - def process_simple_packet_details(self, destination_client_details, mesh_packet, port_num, source_client_details): + def process_simple_packet_details(self, destination_client_details, mesh_packet: MeshPacket, port_num, + source_client_details): common_labels = { 'source_id': source_client_details.node_id, 'source_short_name': source_client_details.short_name, @@ -195,6 +205,11 @@ class MessageProcessor: 'destination_role': destination_client_details.role, } + self.message_size_in_bytes.labels( + **common_labels, + portnum=self.get_port_name_from_portnum(port_num) + ).observe(sys.getsizeof(mesh_packet)) + self.source_message_type_counter.labels( **common_labels, portnum=self.get_port_name_from_portnum(port_num) diff --git a/exporter/processors.py b/exporter/processors.py index eb9b269..eacda36 100644 --- a/exporter/processors.py +++ b/exporter/processors.py @@ -80,12 +80,7 @@ class UnknownAppProcessor(Processor): class TextMessageAppProcessor(Processor): def process(self, payload: bytes, client_details: ClientDetails): logger.debug("Received TEXT_MESSAGE_APP packet") - message = payload.decode('utf-8') - if os.getenv('HIDE_MESSAGE', 'true') == 'true': - message = 'Hidden' - self.metrics.message_length_histogram.labels( - **client_details.to_dict() - ).observe(len(message)) + pass @ProcessorRegistry.register_processor(PortNum.REMOTE_HARDWARE_APP) diff --git a/exporter/registry.py b/exporter/registry.py index 99c591b..ec53d56 100644 --- a/exporter/registry.py +++ b/exporter/registry.py @@ -1,6 +1,6 @@ import geopy.point from geopy.geocoders import Nominatim -from prometheus_client import CollectorRegistry, Counter, Gauge, Histogram +from prometheus_client import CollectorRegistry, Counter, Gauge from exporter.client_details import ClientDetails from exporter.db_handler import DBHandler @@ -29,21 +29,12 @@ class _Metrics: ] def _init_metrics(self): - self._init_metrics_text_message() self._init_metrics_telemetry_device() self._init_metrics_telemetry_environment() self._init_metrics_telemetry_air_quality() self._init_metrics_telemetry_power() self._init_route_discovery_metrics() - def _init_metrics_text_message(self): - self.message_length_histogram = Histogram( - 'text_message_app_length', - 'Length of text messages processed by the app', - self._get_common_labels(), - registry=self._registry - ) - def update_metrics_position(self, latitude, longitude, altitude, precision, client_details: ClientDetails): point = geopy.point.Point(latitude, longitude, altitude) location = self.geolocator.reverse(point, language='en')