influxdb/telegraf mqtt消费者解析,值命名不正确

问题描述 投票:0回答:3

我有这个电报配置

[[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 将值保存到“温度”

在这里您可以看到 mqtt 资源管理器视图:

mqtt explorer view

mqtt influxdb telegraf
3个回答
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/


0
投票
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


-1
投票

嗨,我目前似乎有同样的问题,但无法找到答案。您可以粘贴整个 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"
  1. 它创建了一个新的衡量标准,一点也不差。
  2. 它仍然将值写入字段/标签“值”。
  3. 字段 chn0 获取原始值。

在我的第一个代码片段中,我只是将每个通道(我有三个不同的通道)放入不同的测量中,但从我的角度来看,这不是一个好的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.