mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2025-02-02 07:41:11 -08:00
Removed metric on message size in char len and replaced with overall size of packet by common labels and portnum
This commit is contained in:
parent
ea3f00b466
commit
821056664e
2
.env
2
.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==
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue