Use the TICK stack on Windows 10 with Batch Updates
By: Shan Desai
Tags: Kapacitor, Influxdb, Windows 10, IoT, Telegraf

Component 2: Telegraf

Download Telegraf for Windows through the InfluxData Downloads Page

Fireup the PowerShell WINDOWS + R and type powershell Copy the wget command from the Downloads page above in an appropriate folder e.g. C:\Users\<user>\Dev\ and paste it into PowerShell. You can switch back and forth between Powershell and WSL by:

1. Typing bash in the PowerShell to enter WSL

2. Typing exit in WSL to return back to PowerShell I did not have unzip command in PowerShell, hence I triggered the command using WSL (follow Step 3.1 to achieve this)

The following steps should create a folder telegraf in your desired folder with all extracted files for Telegraf. In general these two files are available: telegraf.exe , telegraf.conf

TIP: In PowerShell, like Linux use the TAB key for autocompletion.

For help regarding all command line options for Telegraf use:

C:\Users\<user>\Dev\telegraf> .\telegraf.exe --help

Generate a Test Configuration

Use a test configuration file for Telegraf by using:

.\telegraf.exe config > telegraf_test.conf

This command should produce telegraf_test.conf in the same folder. In oder to obtain an overview of the generate file use:

cat .\telegraf_test.conf

Adapt Configuration and MQTT Subscribe

I removed all other configurations and kept [[inputs.mqtt_consumer]] and [[outputs.influxdb]] in the configuration file. The variables within the section important were topics (for Subscribe), client_id and servers (address of your MQTT Broker) as well as data_format (since incoming data is JSON)

My file looks like the following:

[[inputs.mqtt_consumer]]

servers = ["tcp://my_mqtt_broker_ip_address:1883"]

qos = 0

connection_timeout = "30s" ## Topics to subscribe to

topics = [

"sensors/env/test"

]

persistent_session = false

# If empty, a random client ID will be generated.

client_id = "DES_Telegraf"

## Each data format has its own unique set of configuration options, read

## more about them here:

## ## Data format to consume.## Each data format has its own unique set of configuration options, read## more about them here:## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md data_format = "json"

json_name_key = "n" # store the values as measurement names

tag_keys = ["bn", "u"] # store these JSON keys as tags

urls = [" [[outputs.influxdb]]urls = [" http://127.0.0.1:8086 "] ## The target database for metrics; will be created as needed.

database = "telegraf_test"

skip_database_creation = false

retention_policy = ""

write_consistency = "any"

## Timeout for HTTP messages.

timeout = "5s"

Automatic metadata storage

The data-format="json" makes it very easy to store information into InfluxDB with its respective metadata. In case of SenML I use the following storage concept:

The n key in SenML is the name of the measurement e.g. humid , temp

key in SenML is the name of the e.g. , The bn and u (unit) should be stored as tags for each value

Exception: Due to bn existing in only one of the JSON element of the array in our SenML structure, the tag bn will only be available in the humid measurement. Adapt your SenML structure accordingly to get same tags for both measurements

Fire up Telegraf

In order to execute Telegraf with the custom configuration use the following command in PowerShell (remember TAB key is your friend):

.\telegraf.exe -config .\telegraf_test.conf

Note: Since InfluxDB is not yet setup the intial trigger of Telegraf will keep logging errors on the console when sending data from MQTT Broker to InfluxDB.