【问题标题】:influxdb/telegraf mqtt consumer parsing, value is not named correctlyinfluxdb/telegraf mqtt 消费者解析,值未正确命名
【发布时间】:2023-01-22 16:46:40
【问题描述】:
嗨,有这个 telegraf 配置
[[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"
我通过 mqtt 将主题推送到“battery/hamburg/devicename2312/temperature”,有效负载是 Temperatur 的值。位置汉堡应该被标记(站点)并且设备名称应该被标记。除了值未正确命名外,它可以正常工作,请参阅 influxdb 日志:
battery,device_name=101A14420210010,host=5cc0065d3907,site=hamburg,topic=battery/hamburg/101A14420210010/temperature value=23.35001,temperature="temperature" 1653991738177023790 telegraf_1 |
我现在在我的涌入数据库中有“值”和值为“温度”的“温度”(作为字符串)。我只希望 telegraf 将值保存为“温度”
Here you see the mqtt explorer view
【问题讨论】:
标签:
mqtt
influxdb
telegraf
【解决方案1】:
经过数小时的谷歌搜索和阅读后,它现在可以工作了。
这是配置的更改部分:
[[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"
更多信息在这里:
https://www.influxdata.com/blog/pivot-mqtt-plugin/
【解决方案2】:
嗨,我目前似乎有同样的问题,但无法为我找到答案。您能否粘贴整个 mqtt 消费者配置? inputs.mqtt_consumer 也是如此。
地雷目前看起来像那样
[[inputs.mqtt_consumer]]
name_override = "chn0"
servers = ["tcp://127.0.0.1:1883"]
topics = [
"vzlogger/data/chn0/raw/#"
]
data_format = "json"
我试图使您的代码适应我的代码,但我的行为很奇怪。
[[inputs.mqtt_consumer]]
servers = ["tcp://127.0.0.1:1883"]
topics = [
"vzlogger/data/chn0/raw"
]
data_format = "value"
data_type = "float"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "vzlogger/+/chn0/+"
measurement = "measurement/_/_/_"
tags = "_/_/channel/_"
fields = "_/_/_/chn0"
[[processors.pivot]]
tag_key = "field"
value_key = "value"
- 它创建了一个新的测量值,它一点也不差。
- 它仍然将值写入字段/标签“值”。
- 字段 chn0 获取原始值。
在我的第一个代码 sn-p 中,我只是将每个通道(我有三个不同的通道)放入不同的测量中,但从我的角度来看,这不是一个好的解决方案。
【解决方案3】:
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