Code Monkey home page Code Monkey logo

meshtastic-metrics-exporter's Introduction

Meshtastic Metrics Exporter

CodeQL

The meshtastic-metrics-exporter is a tool designed to export nearly all available data from an MQTT server to a Prometheus server. It comes with a pre-configured Grafana dashboard connected to both data sources, allowing users to start creating dashboards immediately.

Features

  • Exports a comprehensive set of metrics from an MQTT server to Prometheus.
  • Comes with a Grafana dashboard configured to connect to both Prometheus and Postgres data sources.
    • Comes with some basic dashboards, see the section below for general view of the dashboards
  • Stores node details (ID, short/long name, hardware details, and client type) in a Postgres server, which is also part of the package.
  • Configuration via a .env file.

Grafana Dashboards

The project comes wtih 2 dashboards.

Main Dashboard

SCR-20240707-qgnn

The dashboard has some basic data about the mesh network and it's data is temporarely updated (With new data coming in it would fill out the missing pieces automatically)

User Panel

SCR-20240707-qhth

This panel can be reached from the "Node ID" link on the main dashboard (The table in the center) or you can go to it from the dashbaords tab in grafana and select the node you want to spectate. This board includes some telemetry data and basic information about the node.

The Node Graph

SCR-20240707-qjaj

Both boards also include node graph which allows you to view nodes which are sending Neighbour Info packets As long as we have some node which is connected to our MQTT server the data would be read buy the exporter and parsed as node graph. The line colors indicate the SNR value and the arrow is the direction of the flow captured (It can be two way). And the node circle color indicates which node is connected to MQTT (Green) which one is disconnected from MQTT (Red) and unknown (Gray - Never connected to the MQTT server)

I highly recomend giving the system to stabilize over 24 hours before seeking any useful information from it.

Exported Metrics

๐Ÿท๏ธ Common Labels: node_id, short_name, long_name, hardware_model, role

Label Notation:

  • ๐Ÿท๏ธ: Indicates that all common labels are used.
  • ๐Ÿท๏ธ (source): Indicates that all common labels are used, prefixed with "source_" (e.g., source_node_id, source_short_name, etc.).
  • ๐Ÿท๏ธ (destination): Indicates that all common labels are used, prefixed with "destination_" (e.g., destination_node_id, destination_short_name, etc.).

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 ๐Ÿท๏ธ
device_latitude Device latitude Gauge ๐Ÿท๏ธ
device_longitude Device longitude Gauge ๐Ÿท๏ธ
device_altitude Device altitude Gauge ๐Ÿท๏ธ
device_position_precision Device position precision Gauge ๐Ÿท๏ธ
telemetry_app_ch1_voltage Voltage measured by the device on channel 1 Gauge ๐Ÿท๏ธ
telemetry_app_ch1_current Current measured by the device on channel 1 Gauge ๐Ÿท๏ธ
telemetry_app_ch2_voltage Voltage measured by the device on channel 2 Gauge ๐Ÿท๏ธ
telemetry_app_ch2_current Current measured by the device on channel 2 Gauge ๐Ÿท๏ธ
telemetry_app_ch3_voltage Voltage measured by the device on channel 3 Gauge ๐Ÿท๏ธ
telemetry_app_ch3_current Current measured by the device on channel 3 Gauge ๐Ÿท๏ธ
telemetry_app_pm10_standard Concentration Units Standard PM1.0 Gauge ๐Ÿท๏ธ
telemetry_app_pm25_standard Concentration Units Standard PM2.5 Gauge ๐Ÿท๏ธ
telemetry_app_pm100_standard Concentration Units Standard PM10.0 Gauge ๐Ÿท๏ธ
telemetry_app_pm10_environmental Concentration Units Environmental PM1.0 Gauge ๐Ÿท๏ธ
telemetry_app_pm25_environmental Concentration Units Environmental PM2.5 Gauge ๐Ÿท๏ธ
telemetry_app_pm100_environmental Concentration Units Environmental PM10.0 Gauge ๐Ÿท๏ธ
telemetry_app_particles_03um 0.3um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_particles_05um 0.5um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_particles_10um 1.0um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_particles_25um 2.5um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_particles_50um 5.0um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_particles_100um 10.0um Particle Count Gauge ๐Ÿท๏ธ
telemetry_app_temperature Temperature measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_relative_humidity Relative humidity percent measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_barometric_pressure Barometric pressure in hPA measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_gas_resistance Gas resistance in MOhm measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_iaq IAQ value measured by the device (0-500) Gauge ๐Ÿท๏ธ
telemetry_app_distance Distance measured by the device in mm Gauge ๐Ÿท๏ธ
telemetry_app_lux Ambient light measured by the device in Lux Gauge ๐Ÿท๏ธ
telemetry_app_white_lux White light measured by the device in Lux Gauge ๐Ÿท๏ธ
telemetry_app_ir_lux Infrared light measured by the device in Lux Gauge ๐Ÿท๏ธ
telemetry_app_uv_lux Ultraviolet light measured by the device in Lux Gauge ๐Ÿท๏ธ
telemetry_app_wind_direction Wind direction in degrees measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_wind_speed Wind speed in m/s measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_weight Weight in KG measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_battery_level Battery level of the device (0-100, >100 means powered) Gauge ๐Ÿท๏ธ
telemetry_app_voltage Voltage measured by the device Gauge ๐Ÿท๏ธ
telemetry_app_channel_utilization Utilization for the current channel, including well-formed TX, RX, and noise Gauge ๐Ÿท๏ธ
telemetry_app_air_util_tx Percent of airtime for transmission used within the last hour Gauge ๐Ÿท๏ธ
telemetry_app_uptime_seconds How long the device has been running since the last reboot (in seconds) Counter ๐Ÿท๏ธ
route_length Number of nodes in the route Counter ๐Ÿท๏ธ
route_response Number of responses to route discovery Counter ๐Ÿท๏ธ, response_type
mesh_packet_source_types Types of mesh packets processed by source Counter ๐Ÿท๏ธ (source), portnum
mesh_packet_destination_types Types of mesh packets processed by destination Counter ๐Ÿท๏ธ (destination), portnum
mesh_packet_total Total number of mesh packets processed Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_rx_time Receive time of mesh packets (seconds since 1970) Histogram ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_rx_snr Receive SNR of mesh packets Gauge ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_hop_limit Hop limit of mesh packets Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_want_ack Occurrences of want ACK for mesh packets Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_via_mqtt Occurrences of mesh packets sent via MQTT Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_hop_start Hop start of mesh packets Gauge ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)
mesh_packet_ids Unique IDs for mesh packets Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination), packet_id
mesh_packet_channel Channel used for mesh packets Counter ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination), channel
mesh_packet_rx_rssi Receive RSSI of mesh packets Gauge ๐Ÿท๏ธ (source), ๐Ÿท๏ธ (destination)

Configuration

The project uses a .env file for configuration. Here is an example of the configuration options available:

# Description: Environment variables for the application

# Postgres connection details
DATABASE_URL=postgres://postgres:postgres@postgres:5432/meshtastic

# Prometheus connection details
PROMETHEUS_COLLECTOR_PORT=9464
PROMETHEUS_JOB=example

# MQTT connection details
MQTT_HOST=
MQTT_PORT=1883
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_KEEPALIVE=60
MQTT_TOPIC='msh/israel/#'
MQTT_IS_TLS=false

# Exporter configuration
## Hide source data in the exporter (default: false)
MESH_HIDE_SOURCE_DATA=false
## Hide destination data in the exporter (default: false)
MESH_HIDE_DESTINATION_DATA=false
## Filtered ports in the exporter (default: 1, can be a comma-separated list of ports)
FILTERED_PORTS=0
## 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 messages
MQTT_SERVER_KEY=1PG7OiApB1nwvP+rz05pAQ==

# MQTT protocol version (default: MQTTv5) the public MQTT server supports MQTTv311
# Options: MQTTv311, MQTTv31, MQTTv5
MQTT_PROTOCOL=MQTTv311

# MQTT callback API version (default: VERSION2) the public MQTT server supports VERSION2
# Options: VERSION1, VERSION2
MQTT_CALLBACK_API_VERSION=VERSION2

Running the Project

To run the project, simply use Docker Compose:

docker compose up -d

This command will build and start all the necessary services, including the exporter, Prometheus server, Postgres server, and Grafana.

Grafana Dashboard

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

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

meshtastic-metrics-exporter's People

Contributors

tcivie avatar typicalaimster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

typicalaimster

meshtastic-metrics-exporter's Issues

Issues with docker-compose.yml

When I issue the command docker-compose up --build I get the following output.

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services: 'grafana'
Unsupported config option for volumes: 'grafana_data'
Unsupported config option for networks: 'mesh-bridge'

Running it a second time I get the following

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for volumes: 'grafana_data'
Unsupported config option for networks: 'mesh-bridge'
Unsupported config option for services: 'prometheus'

A third time comes up different again.

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services: 'grafana'
Unsupported config option for networks: 'mesh-bridge'
Unsupported config option for volumes: 'postgres_data'

This is on a CentOS Linux server that I currently have other containers running on.
docker version returns the following

Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:21:09 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:20:06 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Doesnt connect to Meshtastic Public MQTT?

pointing the .env to the meshtastic public mqtt just throws this in the exporter logs

Connected with result code Unsupported protocol version
Connected with result code Unsupported protocol version
Connected with result code Unsupported protocol version
Connected with result code Unsupported protocol version

Node Graph Hide Nodes with no link

Been trying to figure out a way to filter the nodes in the Node Graph panel to not show nodes that don't have a link. We have 200+ nodes but most don't have links so it makes it really hard to view the Node Graph.

MQTT Import Stops

Not sure how to validate this but it's not happened twice. The stack seems to stop ingesting MQTT data. I reboot the VM and it all comes back as normal. Is there logic that if the MQTT connection drops, will it attempt to reconnect?

Error with exporter

Describe the bug
Error in the logs and the exporter not starting

To Reproduce
Steps to reproduce the behavior:

  1. Start things with docker-compose up --build
  2. See error

Expected behavior
For it to work

Additional context

exporter-1    | Traceback (most recent call last):

exporter-1    |   File "/app/main.py", line 8, in <module>

exporter-1    |     from constants import callback_api_version_map, protocol_map

exporter-1    | ModuleNotFoundError: No module named 'constants'

exporter-1 exited with code 1

Persistent data in node graph

old data is persistent. I think nodes should be removed from the graph when neighborinfo doesn't arrive for, say, 12 hours at most. if data is persistent, old data basically sticks around forever if a node goes offline, leading to a very misleading graph.

Exporter Crashes on JSON Parsing

Appears exporter crashes when parsing JSON from MQTT

exporter_1    | Received message on topic 'msh/ANZ/SA/2/json/LongFast/!ebf908b5' at 2024-07-08 05:20:09
exporter_1    | Traceback (most recent call last):
exporter_1    |   File "/app/main.py", line 117, in <module>
exporter_1    |     mqtt_client.loop_forever()
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2297, in loop_forever
exporter_1    |     rc = self._loop(timeout)
exporter_1    |          ^^^^^^^^^^^^^^^^^^^
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1686, in _loop
exporter_1    |     rc = self.loop_read()
exporter_1    |          ^^^^^^^^^^^^^^^^
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2100, in loop_read
exporter_1    |     rc = self._packet_read()
exporter_1    |          ^^^^^^^^^^^^^^^^^^^
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3142, in _packet_read
exporter_1    |     rc = self._packet_handle()
exporter_1    |          ^^^^^^^^^^^^^^^^^^^^^
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3808, in _packet_handle
exporter_1    |     return self._handle_publish()
exporter_1    |            ^^^^^^^^^^^^^^^^^^^^^^
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 4145, in _handle_publish
exporter_1    |     self._handle_on_message(message)
exporter_1    |   File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 4501, in _handle_on_message
exporter_1    |     on_message(self, self._userdata, message)
exporter_1    |   File "/app/main.py", line 58, in handle_message
exporter_1    |     envelope.ParseFromString(message.payload)
exporter_1    | google.protobuf.message.DecodeError: Error parsing message
mosquitto_1   | 1720416009: Client auto-CFAF52D5-A2C5-1AEA-82C3-65047951604B closed its connection.
meshtastic-metrics-exporter_exporter_1 exited with code 1

Change/Add gauge for number of characters in a message

Is your feature request related to a problem? Please describe.
The current metric for the len of the messages we are receiving in the mesh in terms of number of characters is useless and it would be much better to gather information about the number of bytes sent over the mesh.

Describe the solution you'd like
View for each source_user + portnum number of bytes sent (Gauge)

Drop down menu to filter by MQTT Topic

Drop down box on the main dashboard, to be able to drop down and select/filter by subtopics (may also need to setup collector to allow adding more then one topic?)

EG

msh/ANZ
msh/ANZ/SA
msh/ANZ/VIC
msh/US/
msh/US/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.