Solutions

Setup InfluxDB 2.x via Docker with Presets

15min

Overview

Document image


How to deploy InfluxDB 2.x via Docker with presets

Here is an example to run InfluxDB 2.x with Presets with Docker :

IMPORTANT: Litmus has currently verified version 2.5.1, which is why the docker run command will not use the "latest" tag. If a user does decide to choose latest or a later version, the docker run command may have to be adopted in case the vendor influxdata has introduced changes to their product. Therefore, please consult the official docker hub page for potential changes.

Note: The example uses docker running on Ubuntu, as we do not recommend to use Litmus Edge for this.

docker run -itd -p 8086:8086 -v $PWD/data:/var/lib/influxdb2 -v $PWD/config:/etc/influxdb2 -e DOCKER_INFLUXDB_INIT_MODE=setup -e DOCKER_INFLUXDB_INIT_USERNAME=admin -e DOCKER_INFLUXDB_INIT_PASSWORD=litmusedge-s3cr3t! -e DOCKER_INFLUXDB_INIT_ORG=Litmus -e DOCKER_INFLUXDB_INIT_BUCKET=tsdata -e DOCKER_INFLUXDB_INIT_RETENTION=1w -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=z0bsqi47j0ifnz6982mylpyo2f2r9lq9 influxdb:2.5.1

InfluxDB docker image is available at https://hub.docker.com/_/influxdb

⚠️ When using Docker, the following environment variables can be set before running the container to presetup InfluxDB 2.x.

Environment variables

Description

Sample value

Type

 

DOCKER_INFLUXDB_INIT_MODE

 

Used for bootstrap to set the container initial the setup mode.

 

setup

 

 

String

 

 

DOCKER_INFLUXDB_INIT_USERNAME

 

The username to set for the system's initial super-user (Required).

admin

 

String

 

 

DOCKER_INFLUXDB_INIT_PASSWORD

 

The password to set for the system's initial super-user (Required).

 

litmusedge-s3cr3t!

 

 

String

 

 

DOCKER_INFLUXDB_INIT_ORG

 

The name to set for the system's initial organization (Required)

 

Litmus

 

 

String

 

 

DOCKER_INFLUXDB_INIT_BUCKET

 

The name to set for the system's initial bucket (Required).

 

tsdata

 

 

String

 

 

DOCKER_INFLUXDB_INIT_RETENTION

 

The duration the system's initial bucket should retain data. If not set, the initial bucket will retain data forever.

 

1w (1 week or 168 hours)

 

 

String

 

 

DOCKER_INFLUXDB_INIT_ADMIN_TOKEN

 

The authentication token to associate with the system's initial super-user. If not set, a token will be auto-generated by the system.

To get a token, use any system you have available to generate these.

One option is to use LE Tokens option.

 

z0bsqi47j0ifnz6982mylpyo2f2r9lq9

 

 

String

 

There are additional options to for example:

  • persist data to the current working directory in the host file system

-v $PWD/data:/var/lib/influxdb2

  • persist config to the current working directory in the host file system

-v $PWD/config:/etc/influxdb2

(Optional) How to add the InfluxDB 2.x via Docker with presets solution to Litmus Edge Manager marketplace

Note: This is an optional way to deploy the InfluxDB 2.x with presets on a Litmus Edge. Which is not a recommended way of deploying a time series database for long term storage. This should only be done for development or validation purposes and then replaced by an implementation in a data center or as SaaS.

This deployment requires that a Litmus Edge is connected to a deployed Litmus Edge Manager. The user also should have experience in adding applications to the LEM Marketplace.

Step 1: Download the file InfluxDB_2_x_with_presets.json through the Download button, to import the application to LEM Marketplace.

Step 2: Access the LEM User UI via your browser.

Step 3: Access your company and project and select the Features menu. ​

Document image


Step 4: Select the Marketplace option.​​

Document image


Step 5: Select the catalog you want to use.​​

Document image


Step 6: Select the Add or Import an Application icon.​

Document image


Step 7: Import the downloaded json file. ​

Document image


Step 8: The application is now part of the catalog. ​​

Document image


(Optional) How to deploy InfluxDB 2.x via Docker with presets from Litmus Edge Manager marketplace

Note: This is an optional way to deploy the InfluxDB 2.x with presets on a Litmus Edge. Which is not a recommended way of deploying a time series database for long term storage. This should only be done for development or validation purposes and then replaced by an implementation in a data center or as SaaS.

This deployment requires that a Litmus Edge is connected and that the solution has been added to a LEM Marketplace catalog previously.

It is expected, that users are knowledgeable about how applications and solutions are deployed from LEM.

Deploying InfluxDB 2.x with presets from LEM requires a series of parameters to be provided.

Document image


Parameter

Description

Sample value

Type

USERNAME

The username to set for the system's initial super-user (Required). -> used to set environmental variable DOCKER_INFLUXDB_INIT_USERNAME

admin

String

PASSWORD

The password to set for the system's initial super-user (Required). -> used to set environmental variable DOCKER_INFLUXDB_INIT_PASSWORD

litmusedge-s3cr3t!

String

ORGANIZATION

The name to set for the system's initial organization (Required) -> used to set environmental variable DOCKER_INFLUXDB_INIT_ORG

Litmus

String

BUCKET

The name to set for the system's initial bucket (Required). -> used to set environmental variable DOCKER_INFLUXDB_INIT_BUCKET

tsdata

String

RETENTIONTIME

The duration the system's initial bucket should retain data. If not set, the initial bucket will retain data forever. -> used to set environmental variable DOCKER_INFLUXDB_INIT_RETENTION

1w (1 week or 168 hours)

String

ADMIN_TOKEN

The authentication token to associate with the system's initial super-user. If not set, a token will be auto-generated by the system. -> used to set environmental variable DOCKER_INFLUXDB_INIT_ADMIN_TOKEN

To get a token, use any system you have available to generate these.

One option is to use LE Tokens option.

z0bsqi47j0ifnz6982mylpyo2f2r9lq9

String

RESTART

Defines the restart option for the container. Options are: no, always, on-failure

always

String

PORT

Used to set the port command -p <PORT>:8086.

As by default port 8086 is already be used by the internal Litmus Edge influxDB, port 8086 can not be used.

 

 

 

 

⚠️ This implementation does not provide parameters for the persistent data and configuration.

How to access the newly deployed InfluxDB 2.x

After the container is deployed (use docker ps-a to check).

Document image


A browser can be used to access the standard Influx DB 2.x UI.

Step 1: Open a browser and enter the URL for the InfluxDB 2.x UI.

URL: http://<IP of Influx DB>:8086

Example: http://192.168.2.54:8086

Document image


Step 2: Use the username and password from the docker run command to logon.

Step 3: You will now log on to the organization provided in the docker run command.

Document image


How to publish data to the newly deploy InfluxDB 2.x

There are several choices for users to send data from Litmus Edge directly to the newly deployed InfluxDB 2.x

  1. Use the Litmus Edge DataHub External option.
  2. Use the Litmus Edge Integration for Influx DB 2.x.
  3. Use the Litmus Solution LE-Native To InfluxDB v2.
  4. Use the Litmus Solution LE-MQTT To InfluxDB v2.

Note: All of them will require the API key used in the docker run command, as well as the organization and bucket used in the docker run command.

How to use FluxQL to query data from InfluxDB 2.x

FluxQL is the new query language developed by influxdata to access data from InfluXDB 2.x.

This is a query example taken from Grafana:

from(bucket: "tsdata")  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)  |> filter(fn: (r) =>    r._measurement == "PLC_RC1_CCS_08.5477562D-FEA6-4D43-9376-8F77B01C21D9" and    r._field == "HTR_HTG_SCTemp_PV"  )

To query data with FluxQL, it is required to provide the bucket, which is the same bucket taken from the docker run command.

from(bucket: "tsdata")

The range is sued to query a specific time period and will depend on the application used. In the example, the start and end time is set automatically set by Grafana based on the time period set in the dashboard.

Document image

range(start: v.timeRangeStart, stop:v.timeRangeStop)

The filter basically acts as an equivalent to the from and where clause from InfluxQL.

Where the r._measurement is taking in the role of the from clause and basically can be understood as "table" from a relational DB

The r._field is acting as a kind of where clause and could be seen as equivalent to "Where tag = 'xyz'".

filter(fn: (r) =>    r._measurement == "PLC_RC1_CCS_08.5477562D-FEA6-4D43-9376-8F77B01C21D9" and    r._field == "HTR_HTG_SCTemp_PV"  )

Note: To assist with the development of FluxQL queries, the InfluxDB 2.x UI offers a nice tool in the form of their Data explorer.

Document image


This offers a simple way to navigate the time series and build queries using simple selecting of measurements and fields.

Document image


Optional filters are possible.

Document image


The Script Editor then allows to show the actual FluxQL query.

Document image