Skip to content

Instantly share code, notes, and snippets.

@shantanoo-desai
Created September 3, 2020 13:49
Show Gist options
  • Save shantanoo-desai/5399f98476d0cacc0746a6fa75ef1a1b to your computer and use it in GitHub Desktop.
Save shantanoo-desai/5399f98476d0cacc0746a6fa75ef1a1b to your computer and use it in GitHub Desktop.
Telegraf Configuration to connect to an MQTT Broker and converting Field to a Tag for InfluxDB
[agent]
interval = "2s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 12000000
precision = "ms"
## Logging configuration:
## Run telegraf with debug log messages.
debug = true
## Run telegraf in quiet mode (error log messages only).
quiet = false
## If set to true, do no set the "host" tag in the telegraf agent.
omit_hostname = false
# OUTPUT PLUGIN
[[outputs.influxdb]]
urls = ["https://<MY_INFLUXDBV1_INSTANCE:8086"]
database = "PROJ"
skip_database_creation = false
# User Credentials + TLS Verify settings go here
# PROCESSOR PLUGIN
[[processors.enum]]
order = 1
[[processors.enum.mapping]]
field = "result"
dest = "value"
[processors.enum.mapping.value_mappings]
"GOOD" = 0
"BAD" = 1
[[processors.converter]]
order = 2
[processors.converter.fields]
tag = ["result"]
# INPUT PLUGIN
[[inputs.mqtt_consumer]]
servers = [ "ssl://MY_MQTT_BROKER:8883" ]
# Topics to subscribe to:
topics = [
"PROJ/system/status"
]
# User Credentials and TLS Settings go here.
# Incoming MQTT Payload is in JSON format with fixed schema
data_format = "json"
json_name_key = "name"
json_string_fields = ["result"]
json_time_format = "2006-01-02 15:04:05.000"
json_time_key = "timestamp"
@shantanoo-desai
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment