A small program that subscribes to mqtt channels and publishes the data to an InfluxDB timeseries database.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Dockerfile
LICENSE
README.md
mqtt2influxdb.go
mqtt2influxdb.toml
run.sh

README.md

mqtt2influxdb

mqtt2influxdb is a small and simple program that connects to an MQTT server, subscribes to MQTT topics, and publishes messages received to an InfluxDB database.

Building & installing

First make sure you have setup your Go environment. After having setup your $GOPATH you can do a

go get github.com/mhe/mqtt2influxdb

to install a mqtt2influxdb binary in your $GOPATH/bin.

Alternatively you can clone this repository somewhere (for example in your $GOPATH/src) and install the dependencies

cd mqtt2influxdb 
go get ...

Then build it:

go build .

Which should result in a binary in your working directory.

Running

mqtt2influxdb has a number of commandline options. Invoking mqtt2influxdb -h will print:

mqtt2influxdb
Usage of ./mqtt2influxdb:
  -clientid string
    	ClientID to use when connecting to MQTT broker. (default "mqtt2influxdb")
  -config string
    	Configuration file containing the descriptions how to map MQTT messages to InfluxDB points. (default "mqtt2influxdb.toml")
  -database string
    	Name of the InfluxDB database to use. (default "mqtt")
  -influxdb string
    	InfluxDB host address. Should include both protocol (http or https) and port number. (default "http://localhost:8086")
  -mqtt string
    	MQTT host (including port number). (default "localhost:1883")
  -test
    	Print InfluxDB insert lines to stdout instead of actually submitting data.

Configuration

How to map messages from an mqtt bus to points in a influxdb database is specified in a configuration file (using the TOML format).

Each mapping consists of three items:

  • topic: the mqtt topic to subscribe to. It can contain wildcards (e.g., +).
  • template: a template (using Go's text/template) to build a line according to InfluxDB's line protocol.
  • encoding: specifies the encoding of the message, can be one of four: json, msgpack, binc, or cbor. It can be omitted if a default encoding is specified (the defaultEncoding top-level entry).

See the provided example configuration file for more information.

Running in Docker

A basic Dockerfile is provided to create a docker image to run mqtt2influxdb in. Note that it is relatively unoptimized in terms of size. There are a couple of configuration parameters that can be specified using environment variables:

  • MQTT_HOST
  • INFLUXDB_HOST
  • DATABASE_NAME

Alternatives

Although mqtt2influxdb is fairly flexible due to its template-based approach for building InfluxDB input lines, it might not completely suit you. In that case also consider InfluxData's telegraf.