(though now I am getting: Error in plugin: metric parse error: expected tag at 1:5: “5.25” , not sure why)
I am trying to get to a situation where:
• “cube” is the measurement
• there is a device tag which is that second position (44080D05613C in our example)
• the metric is “voltage” (not value) and a float
I am getting thoroughly confused. Closest I got at some point was having a value metric which carried the voltage value and a “voltage” metric that had a string in it.
But I get: 2022-03-10T18:42:35Z E! [inputs.mqtt_consumer] Error in plugin: unable to convert field 'voltage' to type float: strconv.ParseFloat: parsing "voltage": invalid syntax
Looking at this article from an influxdb source I couldn’t find a way to do this either. @samdillard, maybe you know? Maybe something with a pivot?
But in this case @samdillard , I am not trying to make a tag a value, I am just trying to name the field “voltage”. The metric that’s sent for cube/device_id/voltage is right, it’s a float, I am not embedding a field in the topic name. I just want to change the field name from value to voltage. How would I do that?
@samdillard - do you mind helping, I am not sure how to use it:
[[inputs.mqtt_consumer]]
## Broker URLs for the MQTT server or cluster. To connect to multiple
## clusters or standalone servers, use a separate plugin instance.
## example: servers = ["tcp://localhost:1883"]
## servers = ["ssl://localhost:1883"]
## servers = ["ws://localhost:1883"]
servers = ["tcp://192.168.7.229:1883"]
## Topics that will be subscribed to.
topics = [
"cube/+/voltage",
]
data_format = "value"
data_type = "float"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "cube/+/voltage"
measurement = "measurement/_/_"
tags = "_/device/_"
fields = "_/_/test"
[inputs.mqtt_consumer.topic_parsing.types]
test = "float"
[[processors.pivot]]
## Tag to use for naming the new field.
tag_key = "test"
## Field to use as the value of the new field.
value_key = "voltage"
Sure thing. Given the way you’ve configured the consumer, your Tag will be field=voltage and the Field will be value=<float_value>. For pivot, your tag_key will then be “field” and the value_key will be “value”.
The best way to work this out for your future cases is to have Telegraf print out (with the --test flag or using the file output plugin to “stdout”) the data so you know exactly what your fields and tags are named and what values they have.