Oct 272018

Enterprises produce a huge amount of data from a variety of sources, such as, for instance, sensors. Sensors are used to measure different physical characteristics of a machine, zone, etc., e.g., pressure, ph, temperature and so on. These sensors provide sensor data tags as time series data. In this post, we will save data in InfluxDB, an open-source time series database (TSDB),  using an Apache NiFi dataflow.

In order to simulate data provided by sensors, we will use Apache NiFi Simulator Bundle, which provides a utility that allows for generating random and realistic time series data. This simulator is driven by a configuration file that defines the shape (patterns, noise, cycles, etc.) and then converts that data into a time series value. The configuration file documentation is located here. We will use the following configuration file for generating temperature data randomly (temperature.json):

This file has been built using and modifying some of the configurations downloaded from this page.

Before defining the Apache NiFi dataflow, we will install the Apache NiFi Simulator bundle following this guideline, executing maven statements. We have to navigate to the nifi-simulator-bundle-nar/target directory and copy the nifi-simulator-bundle-nar-1.0-SNAPSHOT.nar file to the Apache NiFi /lib folder and the restart NiFi.

We will design a dataflow as illustrated in the diagram below.

In our example, with this dataflow we will control the temperature of two points or zones (temp-zone1 and temp-zone2) of a machine (machine01)

First processor, GenerateTimeSeriesFlowFile, generate random temperature data driven by the configuration file aforementioned. The properties of this processor are:

Simulator configuration file can be wherever you want, but must be reached by the Apache NiFi server. This processor generate FlowFiles like the following:

In order to save this data in an InfluxDB, we need to convert this format to InfluxDB line protocol. Basically, line protocol is:

Dataflow executes this conversion in two steps. First step is carried out by Convert to InfluxDB line protocol process. In this process we get the part

so that we transform data to this format

Timestamp is in nano-seconds resolution and because of that it ends with six zeros. The properties of this processor are:

We are using a Groovy script engine, and the script body is:

The second step of the conversion is responsibility of ReplaceText process. This process deals with this part of the line protocol:

The properties of this processor are:

${measurement} and ${machine} are general variables

Right clicking on NiFi canvas you get this pop-up menu

Clicking on Variables you will see all variables

The result of this process is:

Finally, we will put the data in an InfluxDB database using a PutInfluxDB proccesor. The properties of this processor are:

Username and Password properties must be set only if your InfluxDB database needs authentication. You also must set connection url properly depending on where your InfluxDB is.

After executing the dataflow, we can consult the data in our InfluxDB.


In this post, we have learned how easy it is to save data in InfluxDB using Apache NiFi with a few concrete processes. Apache NiFi is a versatile tool that easily converts and transforms data without the need to program.

You can try this dataflow out by downloading the template from this gist. You will need to tweak URL, Username and Password properties in PutInfluxDB processor and you will have to add measurement and machine variables.

Sorry, the comment form is closed at this time.