From f32769684eb587103aa0ea4afa61ea7372f166bb Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Sun, 30 Jun 2024 19:20:25 +0300 Subject: [PATCH] Added more metrics to the prometheus exporter --- README.md | 98 +++++++++++----------- exporter/processors.py | 86 +++++++++---------- exporter/registry.py | 182 +++++++++++++++++++++-------------------- 3 files changed, 185 insertions(+), 181 deletions(-) diff --git a/README.md b/README.md index ac83a59..8f389e2 100644 --- a/README.md +++ b/README.md @@ -18,49 +18,49 @@ The following is a list of metrics exported by the `meshtastic-metrics-exporter` | Metric Name | Description | Type | Labels | |-----------------------------------|------------------------------------------------------------------------------|-----------|--------------------------------------| -| text_message_app_length | Length of text messages processed by the app | Histogram | client_id | -| device_latitude | Device latitude | Gauge | client_id | -| device_longitude | Device longitude | Gauge | client_id | -| device_altitude | Device altitude | Gauge | client_id | -| device_position_precision | Device position precision | Gauge | client_id | -| telemetry_app_ch1_voltage | Voltage measured by the device on channel 1 | Gauge | client_id | -| telemetry_app_ch1_current | Current measured by the device on channel 1 | Gauge | client_id | -| telemetry_app_ch2_voltage | Voltage measured by the device on channel 2 | Gauge | client_id | -| telemetry_app_ch2_current | Current measured by the device on channel 2 | Gauge | client_id | -| telemetry_app_ch3_voltage | Voltage measured by the device on channel 3 | Gauge | client_id | -| telemetry_app_ch3_current | Current measured by the device on channel 3 | Gauge | client_id | -| telemetry_app_pm10_standard | Concentration Units Standard PM1.0 | Gauge | client_id | -| telemetry_app_pm25_standard | Concentration Units Standard PM2.5 | Gauge | client_id | -| telemetry_app_pm100_standard | Concentration Units Standard PM10.0 | Gauge | client_id | -| telemetry_app_pm10_environmental | Concentration Units Environmental PM1.0 | Gauge | client_id | -| telemetry_app_pm25_environmental | Concentration Units Environmental PM2.5 | Gauge | client_id | -| telemetry_app_pm100_environmental | Concentration Units Environmental PM10.0 | Gauge | client_id | -| telemetry_app_particles_03um | 0.3um Particle Count | Gauge | client_id | -| telemetry_app_particles_05um | 0.5um Particle Count | Gauge | client_id | -| telemetry_app_particles_10um | 1.0um Particle Count | Gauge | client_id | -| telemetry_app_particles_25um | 2.5um Particle Count | Gauge | client_id | -| telemetry_app_particles_50um | 5.0um Particle Count | Gauge | client_id | -| telemetry_app_particles_100um | 10.0um Particle Count | Gauge | client_id | -| telemetry_app_temperature | Temperature measured by the device | Gauge | client_id | -| telemetry_app_relative_humidity | Relative humidity percent measured by the device | Gauge | client_id | -| telemetry_app_barometric_pressure | Barometric pressure in hPA measured by the device | Gauge | client_id | -| telemetry_app_gas_resistance | Gas resistance in MOhm measured by the device | Gauge | client_id | -| telemetry_app_iaq | IAQ value measured by the device (0-500) | Gauge | client_id | -| telemetry_app_distance | Distance measured by the device in mm | Gauge | client_id | -| telemetry_app_lux | Ambient light measured by the device in Lux | Gauge | client_id | -| telemetry_app_white_lux | White light measured by the device in Lux | Gauge | client_id | -| telemetry_app_ir_lux | Infrared light measured by the device in Lux | Gauge | client_id | -| telemetry_app_uv_lux | Ultraviolet light measured by the device in Lux | Gauge | client_id | -| telemetry_app_wind_direction | Wind direction in degrees measured by the device | Gauge | client_id | -| telemetry_app_wind_speed | Wind speed in m/s measured by the device | Gauge | client_id | -| telemetry_app_weight | Weight in KG measured by the device | Gauge | client_id | -| telemetry_app_battery_level | Battery level of the device (0-100, >100 means powered) | Gauge | client_id | -| telemetry_app_voltage | Voltage measured by the device | Gauge | client_id | -| telemetry_app_channel_utilization | Utilization for the current channel, including well-formed TX, RX, and noise | Gauge | client_id | -| telemetry_app_air_util_tx | Percent of airtime for transmission used within the last hour | Gauge | client_id | -| telemetry_app_uptime_seconds | How long the device has been running since the last reboot (in seconds) | Counter | client_id | -| route_length | Number of nodes in the route | Counter | client_id | -| route_response | Number of responses to route discovery | Counter | client_id, response_type | +| text_message_app_length | Length of text messages processed by the app | Histogram | node_id | +| device_latitude | Device latitude | Gauge | node_id | +| device_longitude | Device longitude | Gauge | node_id | +| device_altitude | Device altitude | Gauge | node_id | +| device_position_precision | Device position precision | Gauge | node_id | +| telemetry_app_ch1_voltage | Voltage measured by the device on channel 1 | Gauge | node_id | +| telemetry_app_ch1_current | Current measured by the device on channel 1 | Gauge | node_id | +| telemetry_app_ch2_voltage | Voltage measured by the device on channel 2 | Gauge | node_id | +| telemetry_app_ch2_current | Current measured by the device on channel 2 | Gauge | node_id | +| telemetry_app_ch3_voltage | Voltage measured by the device on channel 3 | Gauge | node_id | +| telemetry_app_ch3_current | Current measured by the device on channel 3 | Gauge | node_id | +| telemetry_app_pm10_standard | Concentration Units Standard PM1.0 | Gauge | node_id | +| telemetry_app_pm25_standard | Concentration Units Standard PM2.5 | Gauge | node_id | +| telemetry_app_pm100_standard | Concentration Units Standard PM10.0 | Gauge | node_id | +| telemetry_app_pm10_environmental | Concentration Units Environmental PM1.0 | Gauge | node_id | +| telemetry_app_pm25_environmental | Concentration Units Environmental PM2.5 | Gauge | node_id | +| telemetry_app_pm100_environmental | Concentration Units Environmental PM10.0 | Gauge | node_id | +| telemetry_app_particles_03um | 0.3um Particle Count | Gauge | node_id | +| telemetry_app_particles_05um | 0.5um Particle Count | Gauge | node_id | +| telemetry_app_particles_10um | 1.0um Particle Count | Gauge | node_id | +| telemetry_app_particles_25um | 2.5um Particle Count | Gauge | node_id | +| telemetry_app_particles_50um | 5.0um Particle Count | Gauge | node_id | +| telemetry_app_particles_100um | 10.0um Particle Count | Gauge | node_id | +| telemetry_app_temperature | Temperature measured by the device | Gauge | node_id | +| telemetry_app_relative_humidity | Relative humidity percent measured by the device | Gauge | node_id | +| telemetry_app_barometric_pressure | Barometric pressure in hPA measured by the device | Gauge | node_id | +| telemetry_app_gas_resistance | Gas resistance in MOhm measured by the device | Gauge | node_id | +| telemetry_app_iaq | IAQ value measured by the device (0-500) | Gauge | node_id | +| telemetry_app_distance | Distance measured by the device in mm | Gauge | node_id | +| telemetry_app_lux | Ambient light measured by the device in Lux | Gauge | node_id | +| telemetry_app_white_lux | White light measured by the device in Lux | Gauge | node_id | +| telemetry_app_ir_lux | Infrared light measured by the device in Lux | Gauge | node_id | +| telemetry_app_uv_lux | Ultraviolet light measured by the device in Lux | Gauge | node_id | +| telemetry_app_wind_direction | Wind direction in degrees measured by the device | Gauge | node_id | +| telemetry_app_wind_speed | Wind speed in m/s measured by the device | Gauge | node_id | +| telemetry_app_weight | Weight in KG measured by the device | Gauge | node_id | +| telemetry_app_battery_level | Battery level of the device (0-100, >100 means powered) | Gauge | node_id | +| telemetry_app_voltage | Voltage measured by the device | Gauge | node_id | +| telemetry_app_channel_utilization | Utilization for the current channel, including well-formed TX, RX, and noise | Gauge | node_id | +| telemetry_app_air_util_tx | Percent of airtime for transmission used within the last hour | Gauge | node_id | +| telemetry_app_uptime_seconds | How long the device has been running since the last reboot (in seconds) | Counter | node_id | +| route_length | Number of nodes in the route | Counter | node_id | +| route_response | Number of responses to route discovery | Counter | node_id, response_type | | mesh_packet_source_types | Types of mesh packets processed by source | Counter | source_id, portnum | | mesh_packet_destination_types | Types of mesh packets processed by destination | Counter | destination_id, portnum | | mesh_packet_total | Total number of mesh packets processed | Counter | source_id, destination_id | @@ -81,11 +81,8 @@ The project uses a `.env` file for configuration. Here is an example of the conf ```dotenv # Description: Environment variables for the application -# Redis connection details -REDIS_HOST=redis -REDIS_PORT=6379 -REDIS_DB=0 -REDIS_PASSWORD= +# Postgres connection details +DATABASE_URL=postgres://postgres:postgres@postgres:5432/meshtastic # Prometheus connection details PROMETHEUS_COLLECTOR_PORT=9464 @@ -121,12 +118,13 @@ To run the project, simply use Docker Compose: docker-compose up --build ``` -This command will build and start all the necessary services, including the MQTT server, Prometheus server, Redis +This command will build and start all the necessary services, including the MQTT server, Prometheus server, Postgres server, and Grafana. ## Grafana Dashboard -The project includes a Grafana dashboard pre-configured to connect to both the Prometheus and Redis data sources. This +The project includes a Grafana dashboard pre-configured to connect to both the Prometheus and Postgres data sources. +This allows you to start creating and customizing your dashboards right away. ## Contributing diff --git a/exporter/processors.py b/exporter/processors.py index 2314a9a..17bb379 100644 --- a/exporter/processors.py +++ b/exporter/processors.py @@ -31,88 +31,93 @@ class MessageProcessor: self.processor_registry = ProcessorRegistry() def init_metrics(self): - # Source-related counters + common_labels = [ + 'source_id', 'source_short_name', 'source_long_name', 'source_hardware_model', 'source_role', + 'destination_id', 'destination_short_name', 'destination_long_name', 'destination_hardware_model', + 'destination_role' + ] + self.source_message_type_counter = Counter( 'mesh_packet_source_types', 'Types of mesh packets processed by source', - ['source_id', 'portnum'], + common_labels + ['portnum'], registry=self.registry ) # Destination-related counters self.destination_message_type_counter = Counter( 'mesh_packet_destination_types', 'Types of mesh packets processed by destination', - ['destination_id', 'portnum'], + common_labels + ['portnum'], registry=self.registry ) # Counters for the total number of packets self.total_packets_counter = Counter( 'mesh_packet_total', 'Total number of mesh packets processed', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Histogram for the rx_time (time in seconds) self.rx_time_histogram = Histogram( 'mesh_packet_rx_time', 'Receive time of mesh packets (seconds since 1970)', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Gauge for the rx_snr (signal-to-noise ratio) self.rx_snr_gauge = Gauge( 'mesh_packet_rx_snr', 'Receive SNR of mesh packets', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Counter for hop_limit self.hop_limit_counter = Counter( 'mesh_packet_hop_limit', 'Hop limit of mesh packets', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Counter for want_ack (occurrences of want_ack set to true) self.want_ack_counter = Counter( 'mesh_packet_want_ack', 'Occurrences of want ACK for mesh packets', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Counter for via_mqtt (occurrences of via_mqtt set to true) self.via_mqtt_counter = Counter( 'mesh_packet_via_mqtt', 'Occurrences of mesh packets sent via MQTT', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Gauge for hop_start self.hop_start_gauge = Gauge( 'mesh_packet_hop_start', 'Hop start of mesh packets', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) # Counter for unique packet IDs self.packet_id_counter = Counter( 'mesh_packet_ids', 'Unique IDs for mesh packets', - ['source_id', 'destination_id', 'packet_id'], + common_labels + ['packet_id'], registry=self.registry ) # Counter for the channel used self.channel_counter = Counter( 'mesh_packet_channel', 'Channel used for mesh packets', - ['source_id', 'destination_id', 'channel'], + common_labels + ['channel'], registry=self.registry ) # Gauge for the rx_rssi (received signal strength indicator) self.rx_rssi_gauge = Gauge( 'mesh_packet_rx_rssi', 'Receive RSSI of mesh packets', - ['source_id', 'destination_id'], + common_labels, registry=self.registry ) @@ -163,78 +168,73 @@ class MessageProcessor: return 'UNKNOWN_PORT' def process_simple_packet_details(self, destination_client_details, mesh_packet, port_num, source_client_details): + common_labels = { + 'source_id': source_client_details.node_id, + 'source_short_name': source_client_details.short_name, + 'source_long_name': source_client_details.long_name, + 'source_hardware_model': source_client_details.hardware_model, + 'source_role': source_client_details.role, + 'destination_id': destination_client_details.node_id, + 'destination_short_name': destination_client_details.short_name, + 'destination_long_name': destination_client_details.long_name, + 'destination_hardware_model': destination_client_details.hardware_model, + 'destination_role': destination_client_details.role, + } + self.source_message_type_counter.labels( - source_id=source_client_details.node_id, + **common_labels, portnum=self.get_port_name_from_portnum(port_num) ).inc() self.destination_message_type_counter.labels( - destination_id=destination_client_details.node_id, + **common_labels, portnum=self.get_port_name_from_portnum(port_num) ).inc() - # Increment the total packets counter self.total_packets_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).inc() - # Observe the rx_time in the histogram self.rx_time_histogram.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).observe(mesh_packet.rx_time) - # Set the rx_snr in the gauge self.rx_snr_gauge.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).set(mesh_packet.rx_snr) - # Increment the hop_limit counter self.hop_limit_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).inc(mesh_packet.hop_limit) - # Increment the want_ack counter if want_ack is true if mesh_packet.want_ack: self.want_ack_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).inc() - # Increment the via_mqtt counter if via_mqtt is true if mesh_packet.via_mqtt: self.via_mqtt_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).inc() - # Set the hop_start in the gauge self.hop_start_gauge.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).set(mesh_packet.hop_start) - # Increment the unique packet ID counter self.packet_id_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id, + **common_labels, packet_id=mesh_packet.id ).inc() # Increment the channel counter self.channel_counter.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id, + **common_labels, channel=mesh_packet.channel ).inc() # Set the rx_rssi in the gauge self.rx_rssi_gauge.labels( - source_id=source_client_details.node_id, - destination_id=destination_client_details.node_id + **common_labels ).set(mesh_packet.rx_rssi) def _get_client_details(self, node_id: int) -> ClientDetails: diff --git a/exporter/registry.py b/exporter/registry.py index 5a0272c..e8edfb9 100644 --- a/exporter/registry.py +++ b/exporter/registry.py @@ -31,6 +31,12 @@ class _Metrics: self._init_metrics() self.initialized = True # Attribute to indicate initialization + @staticmethod + def _get_common_labels(): + return [ + 'node_id', 'short_name', 'long_name', 'hardware_model', 'role' + ] + def _init_metrics(self): # TODO: Go over the metrics and rethink some of them to be more like the longtitute and # latitude - The values should represent something and we shouldn't just label stuff. Also, the labels should # be less used looked upon like keys for the data @@ -47,7 +53,7 @@ class _Metrics: self.message_length_histogram = Histogram( 'text_message_app_length', 'Length of text messages processed by the app', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -55,25 +61,25 @@ class _Metrics: self.device_latitude_gauge = Gauge( 'device_latitude', 'Device latitude', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.device_longitude_gauge = Gauge( 'device_longitude', 'Device longitude', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.device_altitude_gauge = Gauge( 'device_altitude', 'Device altitude', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.device_position_precision_gauge = Gauge( 'device_position_precision', 'Device position precision', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -81,42 +87,42 @@ class _Metrics: self.ch1_voltage_gauge = Gauge( 'telemetry_app_ch1_voltage', 'Voltage measured by the device on channel 1', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ch1_current_gauge = Gauge( 'telemetry_app_ch1_current', 'Current measured by the device on channel 1', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ch2_voltage_gauge = Gauge( 'telemetry_app_ch2_voltage', 'Voltage measured by the device on channel 2', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ch2_current_gauge = Gauge( 'telemetry_app_ch2_current', 'Current measured by the device on channel 2', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ch3_voltage_gauge = Gauge( 'telemetry_app_ch3_voltage', 'Voltage measured by the device on channel 3', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ch3_current_gauge = Gauge( 'telemetry_app_ch3_current', 'Current measured by the device on channel 3', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -124,84 +130,84 @@ class _Metrics: self.pm10_standard_gauge = Gauge( 'telemetry_app_pm10_standard', 'Concentration Units Standard PM1.0', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.pm25_standard_gauge = Gauge( 'telemetry_app_pm25_standard', 'Concentration Units Standard PM2.5', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.pm100_standard_gauge = Gauge( 'telemetry_app_pm100_standard', 'Concentration Units Standard PM10.0', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.pm10_environmental_gauge = Gauge( 'telemetry_app_pm10_environmental', 'Concentration Units Environmental PM1.0', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.pm25_environmental_gauge = Gauge( 'telemetry_app_pm25_environmental', 'Concentration Units Environmental PM2.5', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.pm100_environmental_gauge = Gauge( 'telemetry_app_pm100_environmental', 'Concentration Units Environmental PM10.0', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_03um_gauge = Gauge( 'telemetry_app_particles_03um', '0.3um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_05um_gauge = Gauge( 'telemetry_app_particles_05um', '0.5um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_10um_gauge = Gauge( 'telemetry_app_particles_10um', '1.0um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_25um_gauge = Gauge( 'telemetry_app_particles_25um', '2.5um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_50um_gauge = Gauge( 'telemetry_app_particles_50um', '5.0um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.particles_100um_gauge = Gauge( 'telemetry_app_particles_100um', '10.0um Particle Count', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -210,91 +216,91 @@ class _Metrics: self.temperature_gauge = Gauge( 'telemetry_app_temperature', 'Temperature measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.relative_humidity_gauge = Gauge( 'telemetry_app_relative_humidity', 'Relative humidity percent measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.barometric_pressure_gauge = Gauge( 'telemetry_app_barometric_pressure', 'Barometric pressure in hPA measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.gas_resistance_gauge = Gauge( 'telemetry_app_gas_resistance', 'Gas resistance in MOhm measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.iaq_gauge = Gauge( 'telemetry_app_iaq', 'IAQ value measured by the device (0-500)', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.distance_gauge = Gauge( 'telemetry_app_distance', 'Distance measured by the device in mm', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.lux_gauge = Gauge( 'telemetry_app_lux', 'Ambient light measured by the device in Lux', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.white_lux_gauge = Gauge( 'telemetry_app_white_lux', 'White light measured by the device in Lux', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.ir_lux_gauge = Gauge( 'telemetry_app_ir_lux', 'Infrared light measured by the device in Lux', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.uv_lux_gauge = Gauge( 'telemetry_app_uv_lux', 'Ultraviolet light measured by the device in Lux', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.wind_direction_gauge = Gauge( 'telemetry_app_wind_direction', 'Wind direction in degrees measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.wind_speed_gauge = Gauge( 'telemetry_app_wind_speed', 'Wind speed in m/s measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.weight_gauge = Gauge( 'telemetry_app_weight', 'Weight in KG measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -302,14 +308,14 @@ class _Metrics: self.battery_level_gauge = Gauge( 'telemetry_app_battery_level', 'Battery level of the device (0-100, >100 means powered)', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.voltage_gauge = Gauge( 'telemetry_app_voltage', 'Voltage measured by the device', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -317,14 +323,14 @@ class _Metrics: self.channel_utilization_gauge = Gauge( 'telemetry_app_channel_utilization', 'Utilization for the current channel, including well-formed TX, RX, and noise', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.air_util_tx_gauge = Gauge( 'telemetry_app_air_util_tx', 'Percent of airtime for transmission used within the last hour', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -332,7 +338,7 @@ class _Metrics: self.uptime_seconds_counter = Counter( 'telemetry_app_uptime_seconds', 'How long the device has been running since the last reboot (in seconds)', - ['client_id'], + self._get_common_labels(), registry=self._registry ) @@ -340,13 +346,13 @@ class _Metrics: self.route_discovery_counter = Counter( 'route_length', 'Number of nodes in the route', - ['client_id'], + self._get_common_labels(), registry=self._registry ) self.route_discovery_response_counter = Counter( 'route_response', 'Number of responses to route discovery', - ['client_id', 'response_type'], + self._get_common_labels() + ['response_type'], registry=self._registry ) @@ -432,7 +438,7 @@ class TextMessageAppProcessor(Processor): if os.getenv('HIDE_MESSAGE', 'true') == 'true': message = 'Hidden' self.metrics.message_length_histogram.labels( - client_id=client_details.node_id + **client_details.to_dict() ).observe(len(message)) @@ -452,16 +458,16 @@ class PositionAppProcessor(Processor): position = Position() position.ParseFromString(payload) self.metrics.device_latitude_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(position.latitude_i) self.metrics.device_longitude_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(position.longitude_i) self.metrics.device_altitude_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(position.altitude) self.metrics.device_position_precision_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(position.precision_bits) pass @@ -519,7 +525,6 @@ class NodeInfoAppProcessor(Processor): self.execute_db_operation(db_operation) - @ProcessorRegistry.register_processor(PortNum.ROUTING_APP) class RoutingAppProcessor(Processor): def process(self, payload: bytes, client_details: ClientDetails): @@ -527,11 +532,12 @@ class RoutingAppProcessor(Processor): routing = Routing() routing.ParseFromString(payload) self.metrics.route_discovery_response_counter.labels( - client_id=client_details.node_id, + **client_details.to_dict(), response_type=self.get_error_name_from_routing(routing.error_reason) ).inc() - def get_error_name_from_routing(self, error_code): + @staticmethod + def get_error_name_from_routing(error_code): for name, value in Routing.Error.__dict__.items(): if isinstance(value, int) and value == error_code: return name @@ -637,153 +643,153 @@ class TelemetryAppProcessor(Processor): if telemetry.HasField('device_metrics'): device_metrics: DeviceMetrics = telemetry.device_metrics self.metrics.battery_level_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(device_metrics, 'battery_level', 0)) self.metrics.voltage_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(device_metrics, 'voltage', 0)) self.metrics.channel_utilization_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(device_metrics, 'channel_utilization', 0)) self.metrics.air_util_tx_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(device_metrics, 'air_util_tx', 0)) self.metrics.uptime_seconds_counter.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).inc(getattr(device_metrics, 'uptime_seconds', 0)) if telemetry.HasField('environment_metrics'): environment_metrics: EnvironmentMetrics = telemetry.environment_metrics self.metrics.temperature_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'temperature', 0)) self.metrics.relative_humidity_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'relative_humidity', 0)) self.metrics.barometric_pressure_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'barometric_pressure', 0)) self.metrics.gas_resistance_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'gas_resistance', 0)) self.metrics.iaq_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'iaq', 0)) self.metrics.distance_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'distance', 0)) self.metrics.lux_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'lux', 0)) self.metrics.white_lux_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'white_lux', 0)) self.metrics.ir_lux_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'ir_lux', 0)) self.metrics.uv_lux_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'uv_lux', 0)) self.metrics.wind_direction_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'wind_direction', 0)) self.metrics.wind_speed_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'wind_speed', 0)) self.metrics.weight_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(environment_metrics, 'weight', 0)) if telemetry.HasField('air_quality_metrics'): air_quality_metrics: AirQualityMetrics = telemetry.air_quality_metrics self.metrics.pm10_standard_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm10_standard', 0)) self.metrics.pm25_standard_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm25_standard', 0)) self.metrics.pm100_standard_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm100_standard', 0)) self.metrics.pm10_environmental_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm10_environmental', 0)) self.metrics.pm25_environmental_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm25_environmental', 0)) self.metrics.pm100_environmental_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'pm100_environmental', 0)) self.metrics.particles_03um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_03um', 0)) self.metrics.particles_05um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_05um', 0)) self.metrics.particles_10um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_10um', 0)) self.metrics.particles_25um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_25um', 0)) self.metrics.particles_50um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_50um', 0)) self.metrics.particles_100um_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(air_quality_metrics, 'particles_100um', 0)) if telemetry.HasField('power_metrics'): power_metrics: PowerMetrics = telemetry.power_metrics self.metrics.ch1_voltage_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch1_voltage', 0)) self.metrics.ch1_current_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch1_current', 0)) self.metrics.ch2_voltage_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch2_voltage', 0)) self.metrics.ch2_current_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch2_current', 0)) self.metrics.ch3_voltage_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch3_voltage', 0)) self.metrics.ch3_current_gauge.labels( - client_id=client_details.node_id, + **client_details.to_dict() ).set(getattr(power_metrics, 'ch3_current', 0)) @@ -810,7 +816,7 @@ class TraceRouteAppProcessor(Processor): if traceroute.route: route = traceroute.route self.metrics.route_discovery_counter.labels( - client_id=client_details.node_id + **client_details.to_dict() ).inc(len(route))