LuC kY
LuC kY

Reputation: 33

influxdb/telegraf mqtt consumer parsing, value is not named correctly

I have this telegraf configuration

[[inputs.mqtt_consumer]]
  servers = ["tcp://test_mosquitto_1:1883"]
  # data_format = "influx"
  username = "rasp"
  password = "XXXXY"
  topics = [
  "battery/#"
  ]
  data_format = "value"
  data_type = "float" # required

[[inputs.mqtt_consumer.topic_parsing]]
    data_format = "value"
    data_type = "float"
    topic = "battery/+/+/temperature"
    measurement = "measurement/_/_/_"
    tags = "_/site/device_name/_"
    fields = "_/_/_/temperature"
[[inputs.mqtt_consumer.topic_parsing]]
    data_format = "value"
    data_type = "int"
    topic = "battery/+/+/voltage"
    measurement = "measurement/_/_/_"
    tags = "_/site/device_name/_"
    fields = "_/_/_/voltage"

Im pushing topics over mqtt to "battery/hamburg/devicename2312/temperature" and the payload is the value for Temperatur. The location hamburg should be tagged (site) and the device name should be tagged. Everything works except that the value is not named correctly; see influxdb log:

battery,device_name=101A14420210010,host=5cc0065d3907,site=hamburg,topic=battery/hamburg/101A14420210010/temperature value=23.35001,temperature="temperature" 1653991738177023790
telegraf_1   | 

I now have "value" in my influx database and "temperature" (as a string) with value "temperature". I just want Telegraf to save the value to "temperature"

Here you see the mqtt explorer view:

mqtt explorer view

Upvotes: 1

Views: 5219

Answers (2)

LuC kY
LuC kY

Reputation: 33

After hours of googling and reading it works now. Here is the changed part of the config:

[[inputs.mqtt_consumer.topic_parsing]]
    data_format = "value"
    data_type = "float"
    topic = "battery/+/+/temperature"
    measurement = "measurement/_/_/_"
    tags = "_/site/device_name/field"
    fields = "_/_/_/temperature"
    [[processors.pivot]]
    tag_key = "field"
    value_key = "value"

More information here: https://www.influxdata.com/blog/pivot-mqtt-plugin/

Upvotes: 2

user21059189
user21059189

Reputation: 1

battery,device_name=....,host=....,site=hamburg,topic=battery/hamburg/101A14420210010/temperature value=23.35001,temperature="temperature" 1653991738177023790 

[[inputs.mqtt_consumer.topic_parsing]]
    data_format = "value"
    data_type = "float"
    topic = "battery/+/+/temperature"
    measurement = "measurement/_/_/_"
    tags = "_/site/device_name/field" <<<< "field" gets replaced with 
                                    the actual name of the tag which is temperature 
                                    battery/hamburg/101A14420210010/temperature
    fields = "_/_/_/temperature"
    [[processors.pivot]]
    tag_key = "field"             <<<< use the "field" value to replace te next 
                                  value_key which is called "value" 
    value_key = "value"    <<<< replace value=23.35001 in output with temperature=23.35001

Upvotes: 0

Related Questions