Subscribe to MQTT topics and push them to InfluxDB 1.x or v2
Something like Telegraf for MQTT like it does with inputs.mqtt_consumer
and output.influxdb
.
Telegraf has its downsides which sparked the creation of this tool.
Personally I use VictoriaMetrics which is API compatible with InfluxDB. Therefore, I haven't tested this tool with InfluxDB for some time.
- Telegraf uses a loop every n seconds which gets the timing of MQTT messages wrong. This tool handles MQTT messages exactly when they arrive (and buffers them for better performance).
- Telegraf publishes retained messages on startup. Retained messages have happened at some point in time. Time series databases are made for exact times, not some undefined times. This tool only pushes values to InfluxDB when the time is known (right when they are published/received).
- Telegraf uses a lot of resources. This tool is easily able to run on a Raspberry Pi 1 without any problems.
- Some devices use values like
true
oron
which are annoying to visualize. This tool migrates values like this into1.0
and0.0
. - Telegraf publishes the values with a
topic
tag. This is fine but results in a lot of regular expressions in Grafana. This tool also sets the tagstopic1
,topic2
, …; from the end withtopicE1
,topicE2
, … andtopicSegments
for the amount of segments. For example for topicfoo/bar/test
this results in the following tags:topic1=foo
,topic2=bar
,topic3=test
, from the endtopicE1=test
,topicE2=bar
,topicE3=foo
andtopicSegments=3
. Creating queries with them is way easier compared to regex queries and probably also faster to compute for InfluxDB. - Parses payloads with JSON and MessagePack, adding
key{depth}={name}
as tags (besides the topic tags). Example:{"foo": {"bar": 1337}}
→key1=foo,key2=bar
Run mqtt2influxdb --help
.