Last active
July 29, 2020 19:44
-
-
Save shantanoo-desai/c35792ed3a15d4ec9ac5e92be7c90a3f to your computer and use it in GitHub Desktop.
telegraf configuration file that connects to Mosquitto Open broker and pushes data into InfluxDB v1.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For Telegraf v1.13 | |
docker run --name=telegrafv1.13 -v $pwd/telegraf.conf:/etc/telegraf.conf:ro --net=host telegraf:1.13 | |
# For Telegraf v1.15 | |
docker run --name=telegrafv1.15 -v $pwd/telegraf.conf/etc/telegraf.conf:ro --net=host telegraf:1.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IOT/sensor2/temp | |
env,type=A temp=23.39 | |
env,type=B temp=40.00 | |
# IOT/sensor1/acc | |
env,type=A x=0.2 | |
env,type=B x=1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"publishTopics": [ | |
{ | |
"name": "IOT/sensor1/acc" | |
}, | |
{ | |
"name": "IOT/sensor2/temp" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[agent] | |
interval = "20s" | |
round_interval = true | |
metric_batch_size = 1000 | |
metric_buffer_limit = 10000 | |
collection_jitter = "0s" | |
flush_interval = "10s" | |
flush_jitter = "0s" | |
precision = "" | |
debug = true | |
quiet = false | |
hostname = "" | |
omit_hostname = true | |
############################################################# | |
# OUTPUT PLUGINS # | |
############################################################# | |
[[outputs.influxdb]] | |
urls = [ "http://influxdb:8086" ] | |
database = "mqtelegraftest" | |
skip_database_creation = false | |
timeout = "5s" | |
############################################################### | |
# PROCESSOR PLUGINS # | |
############################################################### | |
[[processors.regex]] | |
[[processors.regex.tags]] | |
# use the `topic` tag to extract information from the MQTT Topic | |
key = "topic" | |
# Topic: IOT/<SENSOR_ID>/<measurement> | |
# Extract <SENSOR_ID> | |
pattern = ".*/(.*)/.*" | |
# Replace the first occurrence | |
replacement = "${1}" | |
# Store it in tag called: | |
result_key = "sensorID" | |
[[processors.enum]] | |
[[processors.enum.mapping]] | |
# create a mapping between extracted sensorID and some meta-data | |
tag = "sensorID" | |
dest = "location" | |
[processors.enum.mapping.value_mappings] | |
"sensor1" = "kitchen" | |
"sensor2" = "livingroom" | |
"sensor3" = "bedroom" | |
################################################################## | |
# INPUT PLUGINS # | |
################################################################## | |
[[inputs.mqtt_consumer]] | |
servers = [ "tcp://test.mosquitto.org:1883" ] | |
# Topics to subscribe to: | |
topics = [ | |
"IOT/+/acc", | |
"IOT/+/mag", | |
"IOT/+/gyro", | |
"IOT/+/temp" | |
] | |
# Telegraf will also store the topic as a tag with name `topic` | |
# NOTE: necessary for the Processor REGEX to extract <Sensor_ID> | |
topic_tag = "topic" | |
# Connection timeout | |
connection_timeout = "30s" | |
# Incoming MQTT Payload from Sensor nodes is in InfluxDB Line Protocol strings | |
data_format = "influx" |
Solution
https://gist.github.com/ssoroka/04a10106e55a9915ed74c646dba5b233#file-telegraf-conf-L31-L60
add order
to which processors
need to be executed in which order
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Observations
the
processors.enum
does not work when spinning a container fortelegraf v1.15
and one does not see thelocation
tag being inserted in this resultthe
processors.enum
WORKS only withtelegraf v1.13
Reproduction
mqtelegraftest
test.mosquitto.org
1883