Skip to content

InfluxDB Exporter Example

The InfluxDB exporter example is located in the examples/influxdb_exporter directory. This example shows how to use the InfluxDB Exporter component from inside a container using JSON configuration files.

The container uses component factories to manage components. The registered factories are as follows:

  • Logger component
  • ThreadPool component
  • Scheduler component
  • Core Bus component
  • Virtual Device Service component. This publishes data on the Bus
  • InfluxDB Exporter component. This subscribes to the Bus and writes data that matches the subscription pattern to the specified InfluxDB database
  • Log Exporter component. This subscribes to the data published by the Virtual Device Service on the same topic set by the InfluxDB Exporter component, and outputs it to the log

The container uses component factories to manage components, which are specified in the config/main.json file. The InfluxDB Exporter component is configured using the influxdb_exporter.json file. For further information on the configuration of the InfluxDB Exporter component, see InfluxDB Exporter Component.


There are three instances of the Logger component. One is configured to Info level and is used by the Log Exporter component that logs the messages available to the InfluxDB Exporter as input. The second is configured to log Debug level messages and is used by the InfluxDB exporter. The third is configured to log Warning level messages for reduced verbosity and is used by the other components in this example.

In this example, the InfluxDB component creates a database named influxdb_test if the InfluxDB service is running at the expected URI as specified in the ServerURI field of the InfluxDB component's configuration.

You must set the following environment variable:

Environment Variable Description
XRT_INFLUXDB_SERVICE The location of the InfluxDB server

If the InfluxDB service is running locally, set to

When the container starts, the InfluxDB component receives data on the Bus that matches the device/data pattern.


You must start the InfluxDB service to run this example.

To run the InfluxDB Exporter component example for five seconds, enter the following commands:

cd examples/influxdb_exporter
xrt config 5
The output is similar to the following:
[iot-0-0:1611229402:console:Info] device/data:{"device":"Motor","resource":"MachineState","readings":{"MachineSpeed":{"value":2.00000000e+02,"type":"float32"},"MachineTemp":{"value":3.32666664e+01,"type":"float32"}}}
[iot-0-0:1611229402:console:Debug] data to influxdb: Motor resource="MachineState",MachineSpeed=200.000000,MachineTemp=33.266666
[iot-0-1:1611229404:console:Info] device/data:{"device":"Motor","resource":"MachineState","readings":{"MachineSpeed":{"value":1.98571426e+02,"type":"float32"},"MachineTemp":{"value":3.37999992e+01,"type":"float32"}}}
[iot-0-1:1611229404:console:Debug] data to influxdb: Motor resource="MachineState",MachineSpeed=198.571426,MachineTemp=33.799999

In this output, the messages from the Virtual Device Service are available on the device/data topic, which is the input to the InfluxDB Exporter component, and the data to influxdb entry is the output from the InfluxDB exporter.

Back to top