mesh_metrics
Description
此脚本允许直接与 Meshtastic 节点交互,以通过 mesh 网络轮询中继器的状态。它仅要求计算机配置了 Prometheus 或 Victoria Metrics、node_exporter(目前),以及到 Meshtastic 无线电的串行连接。它不需要互联网访问。 这些脚本适用于特殊场景,因为大多数情况下应运行其中一种客户端配置。如果你需要这个,你不会有丝毫怀疑。

🚀 新的 Python 脚本
meshmetricsd.py
此 Python 脚本导入了 meshtastic-cli 的 Python 函数,从而提供了更高的灵活性。 它拥有与 bash 脚本相同的所有功能,但扩展了若干特性,并且除了节点列表外还需要一个配置文件,这样您仍然可以加密节点列表,并简化运行过程。
🔍 在 bash 脚本可用功能之上增加的特性:
- 守护进程模式 - 可与 openRC 或 systemd 配合使用(可选)
- 原子性 Prometheus 文件写入(可选)
- 为每个节点写入单独的文件,或写入一个文件。
- Prometheus 暴露 Web 推送(可选,存在限制)
- 统计信息,将收集统计信息写入 JSON 文件(可选)
要求
- Python >= 3.9
- Python Meshtastic-cli
- meshmetricsd.py
- meshmetricsd.conf(scripts 文件夹中的 meshmetricsd.conf.example)
- device.csv (任何在 bash 版本中可用的列表,scripts 文件夹中也有 example.lst)
如何使用:
CLI 非常基础,大多数设置位于配置文件中。
$ ./meshmetricsd.py --help
Meshtastic Repeater Telemetry Daemon MTM-v0.98-Daemon, python version: 3.9.6
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Configuration file path
-f, --foreground Run in foreground (don't daemonize)
-p PATH, --pid-file PATH
PID file path (overrides config)
-l PATH, --log-file PATH
Log file path (overrides config)
-u USER, --user USER User to run as (requires root)
-g GROUP, --group GROUP
Group to run as (requires root)
-t, --test-config Test configuration and exit
--version show program's version number and exit
✨ mesh_metrics.sh
要求:
- Prometheus 或 Victoria Metrics
- node_exporter
- Meshtastic_cli
- 通过 USB 或网络连接的 Meshtastic 客户端。
- Prometheus alertmanager,用于更改 geomap 面板中告警节点的颜色(可选)。
如何使用
Usage: -f <dev_file> -d <path/folder> [options]...
Options:
-h This help text.
-d </Path/to/write/directory>
Path to the directory to output files.
-f </path/to/device_file.lst>
Input file. If \"-\", stdin will be used instead.
-i Make individual files for each node in device list.
-l | -L Show what will run from the device list.
-m Connection mode serial|ip (default- serial)
-o <format> Output format of written file
node_exporter - For ingest by Prometheus node_exoprter.
csv - [TODO] Create a comma delimited file.
(Default- node_exporter)
-p <Device_port>|<HOST|IP>
Device serial port, or IP. (default- /dev/ttyACM0)
-P <password> Password for encrypted device file.
-t Passive dwell time between polling each node.
-v Show verbose output/debug
-H <URL> HTTP endpoint to POST metrics to (e.g., http://pushgateway:9091/metrics/job/meshtastic)
Metrics will be sent in Prometheus exposition format after each node collection.
-T <seconds> HTTP timeout for curl requests (default: 10)
-A <header> Additional HTTP header for curl (can be used multiple times)
Example: -A "Authorization: Bearer token123"
-- Do not interpret any more arguments as options.
Device File format is CSV, Only the NodeID is required
NodeID,Contact_Name,LOCATION,LATITUDE,LONGITUDE
NOTE: 必需参数为 -f <path/device.lst> -p <serial_device>
若未定义输出目录,脚本将打印到屏幕上的 stdout。
./mesh_metrics.sh -f dev.lst -p /dev/tty.usbmodem0
使用网络的示例:
./mesh_metrics.sh -f dev.lst -p 192.168.1.21 -m ip
使用
通过 CRON 任务运行,间隔应适合您的网络。网络越大,驻留时间应增加,以保持信道利用率值的真实性并避免丢失指标。
新增命令行选项:
-H : 用于 POST 指标的 HTTP 端点(例如,http://pushgateway:9091/metrics/job/meshtastic) -T : curl 请求的 HTTP 超时时间(默认:10 秒) -A
: 额外的 HTTP 头(可多次使用,用于身份验证等)主要特性:
独立于文件选项:HTTP 发布完全独立于文件写入(-d、-i 选项)
按节点发布:在每个节点收集完成或失败后立即发送指标
正确的 Prometheus 格式:使用正确的 Content-Type 头发送指标,以符合 Prometheus 展示格式
错误处理:包含超时处理和用于调试的详细日志记录
自定义头:支持身份验证头,如 Authorization: Bearer token
使用示例:
# Send to Prometheus Pushgateway
./mesh_metrics.sh -f devices.lst -H "http://pushgateway:9091/metrics/job/meshtastic"
# With authentication and custom timeout
./mesh_metrics.sh -f devices.lst -H "https://api.example.com/metrics" \
-A "Authorization: Bearer abc123" -T 30
# Combined with file output (both happen independently)
./mesh_metrics.sh -f devices.lst -d /var/lib/prometheus \
-H "http://pushgateway:9091/metrics/job/meshtastic"
设备文件
设备文件选项: 仅 NodeID 是必需的,用于轮询节点,但每行都需要表示所有逗号。 其他字段均为可选,但仪表板地图需要 GPS 坐标来发布点。
| 节点 ID | 联系人 | 属性名称 | 纬度 | 经度 |
|---|---|---|---|---|
| !2f67c123 | Jon Derps | Derp Hill | 21.1234 | -122.56789 |
| !2c4354f4 | Dan Mann | The man hill | 21.254554 | -122.56123 |
!2f67c123,Jon Derps,Derp Hill,21.1234,-122.56789
!2c4354f4,Dan Mann,The man hill,21.254554,-122.56123
!56a58b6a,,,,
Grafana
Dashboard 的 geomap 插件可以将告警节点的颜色更改为红色,这需要安装并配置 Prometheus alertmanager。这一要求是 geomap 插件的限制,因为 grafana 没有其他手段来传递该数据,或者完全有可能我只是尚未找到如何从 Grafana 获取该告警数据到 Geomap 插件的方法……(我仍在寻找减少额外依赖的方法)。
加密节点列表
可以使用 ssl 和密码对节点列表进行加密,并以多种方式通过命令行提供该密码。 要加密文件:
# set this to whatever password your scripts will use
DEVFILEPASS="YourSecretPassword"
# encrypt plaintext.csv → plaintext.csv.enc
openssl enc \
-aes-256-cbc \
-pbkdf2 \
-iter 1000 \
-md sha256 \
-salt \
-in plaintext.csv \
-out plaintext.csv.enc \
-pass pass:"${DEVFILEPASS}"
TODO: