Added PAX counter reported metrics to prometheus

This commit is contained in:
Gleb Tcivie 2025-02-25 22:42:32 +02:00
parent ae6f8b4160
commit 60002b20e9
6 changed files with 50 additions and 14 deletions

14
.env
View file

@ -8,13 +8,13 @@ PROMETHEUS_COLLECTOR_PORT=9464
PROMETHEUS_JOB=meshtastic PROMETHEUS_JOB=meshtastic
# MQTT connection details # MQTT connection details
MQTT_HOST=mqtt.meshtastic.org #MQTT_HOST=mqtt.meshtastic.org
MQTT_PORT=1883 #MQTT_PORT=1883
MQTT_USERNAME=meshdev #MQTT_USERNAME=meshdev
MQTT_PASSWORD=large4cats #MQTT_PASSWORD=large4cats
MQTT_KEEPALIVE=60 #MQTT_KEEPALIVE=60
MQTT_TOPIC='msh/EU_868/#,msh/US/#' #MQTT_TOPIC='msh/EU_868/#,msh/US/#'
MQTT_IS_TLS=false #MQTT_IS_TLS=false
# MQTT protocol version (default: MQTTv5) the public MQTT server supports MQTTv311 # MQTT protocol version (default: MQTTv5) the public MQTT server supports MQTTv311
# Options: MQTTv311, MQTTv31, MQTTv5 # Options: MQTTv311, MQTTv31, MQTTv5

View file

@ -9,5 +9,6 @@
</component> </component>
<component name="PackageRequirementsSettings"> <component name="PackageRequirementsSettings">
<option name="versionSpecifier" value="Greater or equal (&gt;=x.y.z)" /> <option name="versionSpecifier" value="Greater or equal (&gt;=x.y.z)" />
<option name="keepMatchingSpecifier" value="false" />
</component> </component>
</module> </module>

View file

@ -192,6 +192,9 @@ Label Notation:
| mesh_packet_ids | Unique packet IDs | Counter | 🏷️ (source), 🏷️ (destination), packet_id | | mesh_packet_ids | Unique packet IDs | Counter | 🏷️ (source), 🏷️ (destination), packet_id |
| mesh_packet_channel | Packet channel | Counter | 🏷️ (source), 🏷️ (destination), channel | | mesh_packet_channel | Packet channel | Counter | 🏷️ (source), 🏷️ (destination), channel |
| mesh_packet_rx_rssi | Packet receive RSSI | Gauge | 🏷️ (source), 🏷️ (destination) | | 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 ## Configuration

View file

@ -1,4 +1,5 @@
from datetime import datetime from datetime import datetime
from prometheus_client import CollectorRegistry, Counter, Gauge from prometheus_client import CollectorRegistry, Counter, Gauge
from exporter.client_details import ClientDetails from exporter.client_details import ClientDetails
@ -35,6 +36,7 @@ class Metrics:
self._init_metrics_telemetry_air_quality() self._init_metrics_telemetry_air_quality()
self._init_metrics_telemetry_power() self._init_metrics_telemetry_power()
self._init_route_discovery_metrics() self._init_route_discovery_metrics()
self._init_pax_counter_metrics()
def update_metrics_position(self, latitude, longitude, altitude, precision, client_details: ClientDetails): def update_metrics_position(self, latitude, longitude, altitude, precision, client_details: ClientDetails):
# Could be used to calculate more complex data (Like distances etc..) # Could be used to calculate more complex data (Like distances etc..)
@ -328,3 +330,23 @@ class Metrics:
self._get_common_labels() + ['response_type'], self._get_common_labels() + ['response_type'],
registry=self._registry 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
)

View file

@ -267,6 +267,16 @@ class PaxCounterAppProcessor(Processor):
except Exception as e: except Exception as e:
logger.error(f"Failed to parse PAXCOUNTER_APP packet: {e}") logger.error(f"Failed to parse PAXCOUNTER_APP packet: {e}")
return 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) @ProcessorRegistry.register_processor(PortNum.SERIAL_APP)

View file

@ -1,14 +1,14 @@
paho-mqtt~=2.1.0 paho-mqtt>=2.1.0
python-dotenv~=1.0.1 python-dotenv>=1.0.1
prometheus_client~=0.20.0 prometheus_client>=0.21.1
unishox2-py3~=1.0.0 unishox2-py3~=1.0.0
cryptography~=44.0.1 cryptography>=44.0.1
psycopg~=3.1.19 psycopg>=3.2.5
psycopg_pool~=3.2.2 psycopg_pool~=3.2.2
psycopg-binary~=3.1.20 psycopg-binary~=3.1.20
geopy>=2.4.1 geopy>=2.4.1
psycopg-pool>=3.2.2 psycopg-pool>=3.2.5
APScheduler>=3.10.4 APScheduler>=3.11.0
# Meshtastic Protocol Buffers # Meshtastic Protocol Buffers
meshtastic-protobufs-protocolbuffers-python==29.3.0.1.20241006120827+cc36fd21e859 meshtastic-protobufs-protocolbuffers-python==29.3.0.1.20241006120827+cc36fd21e859