From 60002b20e9993189793b4f3205d8b7ef942e871a Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Tue, 25 Feb 2025 22:42:32 +0200 Subject: [PATCH] Added PAX counter reported metrics to prometheus --- .env | 14 +++++++------- .idea/meshtastic-metrics-exporter.iml | 1 + README.md | 3 +++ exporter/metric/node_metrics.py | 22 ++++++++++++++++++++++ exporter/processor/processors.py | 10 ++++++++++ requirements.txt | 14 +++++++------- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.env b/.env index da3c9e5..eea4149 100644 --- a/.env +++ b/.env @@ -8,13 +8,13 @@ PROMETHEUS_COLLECTOR_PORT=9464 PROMETHEUS_JOB=meshtastic # MQTT connection details -MQTT_HOST=mqtt.meshtastic.org -MQTT_PORT=1883 -MQTT_USERNAME=meshdev -MQTT_PASSWORD=large4cats -MQTT_KEEPALIVE=60 -MQTT_TOPIC='msh/EU_868/#,msh/US/#' -MQTT_IS_TLS=false +#MQTT_HOST=mqtt.meshtastic.org +#MQTT_PORT=1883 +#MQTT_USERNAME=meshdev +#MQTT_PASSWORD=large4cats +#MQTT_KEEPALIVE=60 +#MQTT_TOPIC='msh/EU_868/#,msh/US/#' +#MQTT_IS_TLS=false # MQTT protocol version (default: MQTTv5) the public MQTT server supports MQTTv311 # Options: MQTTv311, MQTTv31, MQTTv5 diff --git a/.idea/meshtastic-metrics-exporter.iml b/.idea/meshtastic-metrics-exporter.iml index eb9ce46..a2f1da6 100644 --- a/.idea/meshtastic-metrics-exporter.iml +++ b/.idea/meshtastic-metrics-exporter.iml @@ -9,5 +9,6 @@ \ No newline at end of file diff --git a/README.md b/README.md index 50d92f0..10cc795 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,9 @@ Label Notation: | mesh_packet_ids | Unique packet IDs | Counter | 🏷️ (source), 🏷️ (destination), packet_id | | mesh_packet_channel | Packet channel | Counter | 🏷️ (source), 🏷️ (destination), channel | | mesh_packet_rx_rssi | Packet receive RSSI | Gauge | 🏷️ (source), 🏷️ (destination) | +| pax_wifi | Number of Wifi devices (PAX) | Gauge | 🏷 | +| pax_ble | Number of Bluetooth devices (PAX) | Gauge | 🏷 | +| pax_uptime | PAX device uptime | Gauge | 🏷 | ## Configuration diff --git a/exporter/metric/node_metrics.py b/exporter/metric/node_metrics.py index 1b70b09..16802f9 100644 --- a/exporter/metric/node_metrics.py +++ b/exporter/metric/node_metrics.py @@ -1,4 +1,5 @@ from datetime import datetime + from prometheus_client import CollectorRegistry, Counter, Gauge from exporter.client_details import ClientDetails @@ -35,6 +36,7 @@ class Metrics: self._init_metrics_telemetry_air_quality() self._init_metrics_telemetry_power() self._init_route_discovery_metrics() + self._init_pax_counter_metrics() def update_metrics_position(self, latitude, longitude, altitude, precision, client_details: ClientDetails): # Could be used to calculate more complex data (Like distances etc..) @@ -328,3 +330,23 @@ class Metrics: self._get_common_labels() + ['response_type'], registry=self._registry ) + + def _init_pax_counter_metrics(self): + self.pax_wifi_gauge = Gauge( + 'pax_wifi', + 'Number of WiFi devices', + self._get_common_labels(), + registry=self._registry + ) + self.pax_ble_gauge = Gauge( + 'pax_ble', + 'Number of BLE devices', + self._get_common_labels(), + registry=self._registry + ) + self.pax_uptime_gauge = Gauge( + 'pax_uptime', + 'Uptime of the device', + self._get_common_labels(), + registry=self._registry + ) diff --git a/exporter/processor/processors.py b/exporter/processor/processors.py index e8b0aa8..94d4e20 100644 --- a/exporter/processor/processors.py +++ b/exporter/processor/processors.py @@ -267,6 +267,16 @@ class PaxCounterAppProcessor(Processor): except Exception as e: logger.error(f"Failed to parse PAXCOUNTER_APP packet: {e}") return + self.metrics.pax_wifi_gauge.labels( + **client_details.to_dict() + ).set(paxcounter.wifi) + self.metrics.pax_ble_gauge.labels( + **client_details.to_dict() + ).set(paxcounter.ble) + self.metrics.pax_uptime_gauge.labels( + **client_details.to_dict() + ).set(paxcounter.uptime) + @ProcessorRegistry.register_processor(PortNum.SERIAL_APP) diff --git a/requirements.txt b/requirements.txt index b805fb8..59f0335 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ -paho-mqtt~=2.1.0 -python-dotenv~=1.0.1 -prometheus_client~=0.20.0 +paho-mqtt>=2.1.0 +python-dotenv>=1.0.1 +prometheus_client>=0.21.1 unishox2-py3~=1.0.0 -cryptography~=44.0.1 -psycopg~=3.1.19 +cryptography>=44.0.1 +psycopg>=3.2.5 psycopg_pool~=3.2.2 psycopg-binary~=3.1.20 geopy>=2.4.1 -psycopg-pool>=3.2.2 -APScheduler>=3.10.4 +psycopg-pool>=3.2.5 +APScheduler>=3.11.0 # Meshtastic Protocol Buffers meshtastic-protobufs-protocolbuffers-python==29.3.0.1.20241006120827+cc36fd21e859