当我使用电报时,inputs.mqtt_consumer
在订阅mqtt时无法正确解析数据
- 这是我使用emqx从客户端读取的原始数据:
{
"air": "air",
"humidity": 35,
"region": "shanghai",
"temperature": 34,
"time": 1655371268
}
- 这是电报的配置
[[inputs.mqtt_consumer]]
servers = ["tcp://127.0.0.1:1883"]
topics = [
"test/#"
]
data_format = "json"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "air/humidity/region/temperature/time"
measurement = "measurement/_/_/_/_"
tags = "_/_/region/_/_"
fields = "_/_/_/temperature/_"
- 但是我在incluxdb中得到的数据是这样的
> select * from mqtt_consumer
name: mqtt_consumer
time humidity temperature topic
---- -------- ----------- -----
2022-06-16T09:28:45.663600586Z 41 41 test
2022-06-16T09:28:45.764128509Z 38 48 test
2022-06-16T09:28:46.664330569Z 43 47 test
2022-06-16T09:28:46.764848563Z. 41 34 test
2022-06-16T09:28:47.665094746Z. 49 50 test
2022-06-16T09:28:47.765611758Z. 5 50 test
2022-06-16T09:28:48.66629661Z 42 32 test
- 我希望数据是这样的
name: mqtt_consumer
time region temperature topic
---- ---- ----------- -----
2022-06-16T09:28:45.663600586Z shanghai 41 test
2022-06-16T09:28:45.764128509Z shanghai 48 test
2022-06-16T09:28:46.664330569Z shanghai 47 test
2022-06-16T09:28:46.764848563Z shanghai 34 test
2022-06-16T09:28:47.665094746Z shanghai 50 test
2022-06-16T09:28:47.765611758Z shanghai 50 test
2022-06-16T09:28:48.66629661Z shanghai 32 test
- telegraf的配置不能更改为
[[inputs.mqtt_consumer.topic_parsing]]
topic = "air/humidity/region/temperature/time"
measurement = "measurement/_/_/_/_"
tags = "_/_/tag/_/_"
fields = "_/_/_/field/_"
[[inputs.mqtt_consumer]]
data_format = "json"
tag_keys = [
"region"
]
见doc https://docs.influxdata.com/telegraf/v1.22/data_formats/input/json/