Guys,
I have the following working telegraf.conf
[global_tags]
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = "0s"
debug = false
hostname = ""
omit_hostname = false
[[outputs.file]]
files = ["stdout"]
[[inputs.mqtt_consumer]]
alias = "mqtt_consumer_value"
client_id = "telegraf_value"
servers = ["tcp://127.0.0.1:1883"]
username = "UUUU"
password = "pppp"
name_override = "logdata" # measurement
topic_tag = "addr" # tag, instead of "topic"
topics = [
"knx/2/2/2",
"knx/2/0/3",
"mtr/wasser",
"mtr/hzg/temp_VL",
"mtr/hzg/temp_RL",
"mtr/hzg/temp_RLWW",
"knx/4/5/7",
]
data_format = "value"
data_type = "string"
It reads topic / value pairs from mqtt alright. Ultimately, the output will go into InfluxDB but for testing and debugging the [[output.file]]
is active, for the time being.
As you may notice, some topics are cryptic, like “knx/2/2/2”. It would require additional knowledge later-on to interpret what was written to InfluxDB. The approach I have in mind to solve it is like following:
a) create a array of tables (question: where? in the [global_tag]
section?)
b) reference to this table in the [[inputs.mqtt_consumer]]
section (question: how?)
c) and create an additional tag with the “user friendly name” (ufn). (question: how?)
The array of tables could look like:
topicmap = [
{ topic = "knx/2/2/2", ufn = "temperature" },
{ topic = "knx/2/0/3", ufn = "energy" },
]
and the [[inputs.mqtt_consumer]]
may loke like
...
topics = [ topicmap.topic ]
tags = [ topicmap.ufn ]
...
However, while writing, I realize that a construct like that may require an adaptation of the [[inputs.mqtt_consumer]]
plugin…
Does anyone have any insights here to be shared? Or an different approach to tackle my initial problem?
Thanks