# InfluxDB

InfluxDB is a database for storing and analyzing time series data. Its powerful data throughput capability and stable performance make it very suitable to be applied in the field of Internet of Things (IoT).

EMQX now supports connection to mainstream versions of InfluxDB Cloud, InfluxDB OSS, or InfluxDB Enterprise.

Prerequisites

# Feature list

# Quick starts

# Install InfluxDB

  1. Install InfluxDB (opens new window) via Docker, and then run the docker image.
# TO start the InfluxDB docker image
docker run --name influxdb -p 8086:8086 influxdb:2.5.1
1
2
  1. With InfluxDB running, visit http://localhost:8086 (opens new window) Set the Username, Password, Organization Name, and Bucket Name.
  2. In the InfluxDB UI, click Load Data -> API Token and then follow the instructions to create all-access tokens (opens new window).

# Connect to InfluxDB

  1. Go to EMQX Dashboard, click Data Integration -> Data Bridge.
  2. Click Create on the top right corner of the page.
  3. In the Create Data Bridge page, click to select InfluxDB, and then click Next.
  4. Input a name for the data bridge. Note: It should be a combination of upper/lower case letters and numbers.
  5. Select the InfluxDB version as needed, by default v2 is selected.
  6. Input the connection information.
    • For Server Host, input 127.0.0.1:8086. If you are creating a connection to InfluxDB Cloud, use 443 as the port No., that is, input {url}:443 and enable TLS connection.
    • Select Token as the Auth Type. Input the Organization, Bucket, and Token we set in the Install InfluxDB step.
  7. Define data parsing method, including Measurement, Timestamp, Fields and Tags. Note: All key values can be variables and you can also follow the InfluxDB line protocol (opens new window) to set them.
  8. Advanced settings (optional): Choose whether to use sync or async query mode, and whether to enable queue or batch. For details, see Configuration parameters.
  9. Then click Create to finish the setup.

We have successfully created the data bridge to InfluxDB, now we can continue to create rules to specify the data to be saved into InfluxDB.

  1. Go to EMQX Dashboard, click Data Integration -> Rules.
  2. Click Create on the top right corner of the page.
  3. Input my_rule as the rule ID, and set the rules in the SQL Editor. Here we want to save the MQTT messages under topic t/# to InfluxDB, we can use the SQL syntax below. Note: If you are testing with your SQL, please ensure you have included all required fields in the SELECT part.
SELECT 
  *
FROM
  "t/#"
1
2
3
4
  1. Then click the Add Action button, select Forwarding with Data Bridge from the dropdown list and then select the data bridge we just created under Data bridge. Then click the Add button.
  2. Click Create at the page bottom to finish the creation.

Now we have successfully created the data bridge to InfluxDB. You can click Data Integration -> Flows to view the topology. It can be seen that the messages under topic t/# are sent and saved to InfluxDB after parsing by rule my_rule.

# Test

Use MQTTX to send a message to topic t/1 to trigger an online/offline event.

mqttx pub -i emqx_c -t t/1 -m '{ "msg": "hello InfluxDB" }'
1

Check the running status of the two data bridges, there should be one new incoming and one new outgoing message.

In the InfluxDB UI, you can confirm whether the message is written into the InfluxDB via the Data Explorer window.