Ignore Sub Topic in MQTT input in telegraf

Hello,

I’ve a question, I’m running Telegraf Version 1.27.1.
On that I got a input mqtt_consumer configured with data_format = value and data_type = float.

The topic and subtopic I’m parsing is full of numeric values except two. Can I exclude them so that they won’t get processed?
Right now I’m experiencing that Telegraf will stop at all after an amount of time because it’s complaining that:

E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax

When I restart telegraf it will continue to work.

So I tried with topic_parsing and other things I found on the net but didn’t get it working.
That “offline” part is one of the subtopics which is indeed string. See the below screenshot of the structure.

Can someone give me a hint how to configure the input correctly and parsing the status part or ignoring it?

Thanks!

I didn’t expect telegraf to stop due to an error during parsing. Are you certain there isn’t another error?

@fork can you please try the binary in feat(parsers.value): Add support for automatic fallback for numeric types by srebhan · Pull Request #13506 · influxdata/telegraf · GitHub with data_type = "auto_float" and let me know if this works for you!? This new setting allows to fallback to a string if the value in the topic is not a floating-point value…

Yes it will stop to process. For testing I separated the mqtt input topic with the string float mix from the others and only that is not processing anymore. Here is the the log taken right now:

2023-06-23T21:45:57Z I! Loading config: /etc/telegraf/telegraf.conf
2023-06-23T21:45:57Z I! Starting Telegraf 1.27.1
2023-06-23T21:45:57Z I! Available plugins: 237 inputs, 9 aggregators, 28 processors, 23 parsers, 59 outputs, 4 secret-stores
2023-06-23T21:45:57Z I! Loaded inputs: mqtt_consumer (2x)
2023-06-23T21:45:57Z I! Loaded aggregators:
2023-06-23T21:45:57Z I! Loaded processors:
2023-06-23T21:45:57Z I! Loaded secretstores:
2023-06-23T21:45:57Z I! Loaded outputs: influxdb_v2
2023-06-23T21:45:57Z I! Tags enabled: host=telegrafProx
2023-06-23T21:45:57Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:“telegrafProx”, Flush Interval:10s
2023-06-23T21:45:57Z I! [inputs.mqtt_consumer] Connected [tcp://mqtt:1883]
2023-06-23T21:45:57Z I! [inputs.mqtt_consumer] Connected [tcp://mqtt:1883]
2023-06-23T21:45:57Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “online”: invalid syntax
2023-06-23T21:45:57Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “online”: invalid syntax
2023-06-23T21:46:02Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:46:20Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:46:32Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:46:50Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:47:02Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:47:20Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:47:32Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:47:50Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:48:02Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:48:20Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:48:32Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:48:50Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-23T21:49:02Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
…CUT…
2023-06-24T01:54:32Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-24T01:54:50Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-24T01:55:02Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax
2023-06-24T01:55:20Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing “offline”: invalid syntax

These were the last lines. As you can the the input processing stopped at the 24th. And as of today it’s the 30th.
The other inputs in the configuration (also mqtt) are still working without an error.

@fork,

We’ve had another user who is using the mqtt_consumer plugin, who also gets parsing errors also run into the plugin stop collecting data. Can you try the artifact in fix(inputs.mqtt_consumer): add client debug by powersj · Pull Request #13478 · influxdata/telegraf · GitHub and provide the logs?

Thanks

Hi sorry for the late reply.
Can you provide or update the repo with a Dockerfile so that I can build a image for testing?
I’ve checked the makefile, there is a

docker-image

directive with points to

scripts/buster.docker

but that Dockerfile doesn’t exists in the folder.

I already build the versions but I like to swap the container on my hosting server which runs atm the official telegraf image. And because there must be a Dockerfile somewhere, maybe you can provide it before I’ve to write my own :slight_smile:

We do not provide or build Docker images for every PR, that would be a lot :wink:

The official docker images use Telegraf from a repo, so that won’t be much use to you. What I do locally is use a Dockerfile like this when I want to take a local build and try it out:

FROM archlinux 

COPY telegraf /usr/bin/telegraf

CMD ["/usr/bin/telegraf"]

Hey I saw that both PRs are merged into master and a new version is released.
I don’t know if your client debug part is in master but now I got this, when things stop working:

2023-07-12T11:36:26Z I! Loading config: /etc/telegraf/telegraf.conf
2023-07-12T11:36:26Z I! Starting Telegraf 1.27.2
2023-07-12T11:36:26Z I! Available plugins: 237 inputs, 9 aggregators, 28 processors, 23 parsers, 59 outputs, 4 secret-stores
2023-07-12T11:36:26Z I! Loaded inputs: mqtt_consumer (2x)
2023-07-12T11:36:26Z I! Loaded aggregators:
2023-07-12T11:36:26Z I! Loaded processors:
2023-07-12T11:36:26Z I! Loaded secretstores:
2023-07-12T11:36:26Z I! Loaded outputs: influxdb_v2
2023-07-12T11:36:26Z I! Tags enabled: host=telegrafProx
2023-07-12T11:36:26Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegrafProx", Flush Interval:10s
2023-07-12T11:36:26Z I! [inputs.mqtt_consumer] Connected [tcp://mqtt:1883]
2023-07-12T11:36:26Z I! [inputs.mqtt_consumer] Connected [tcp://mqtt:1883]
2023-07-12T11:49:41Z E! [inputs.mqtt_consumer] could not mark message delivered: 2718
2023-07-12T12:34:13Z E! [inputs.mqtt_consumer] could not mark message delivered: 11788
2023-07-12T13:21:14Z E! [inputs.mqtt_consumer] could not mark message delivered: 21324
2023-07-12T14:32:14Z E! [inputs.mqtt_consumer] could not mark message delivered: 35809

So what’s next to do? Increase debug level somewhere?

The question is: why can it not mark messages as delivered? Is networking blocked in that direction?

I can’t tell you.
Both Hosts are on same subnet without firewall. Nothing blocked and no evidence of something wrong on mosquitto mqtt side.

Does your mosquitto logs show that it is communicating back?

If you get into the telegraf container itself can you communicate or connect to the mosquitto server.

So I checked to logs on mosquitto side. I saw the telegraf connect and no disconnect so far.

Also I tried to connect to the server from the container via shell, and mosquitto is logging it.
So it seems not an network issue. The mosquitto server is also running for more than 2 years very stable without any issues.

Can you update to 1.27.2 we did include a fairy large mqtt fix with that version

It’s already 1.27.2
And the number just increased since then. Maybe you can put a debug option in it, so that I can switch it on?

So found out about the debug options you included with
[agent]
debug = on

and in the MQTT section. In the meantime we are at 1.27.4 and it’s working without issues! So something had been fixed!
Thanks for your effort @jpowers !

@srebhan I tried your auto_float implementation. Sadly it is not writing any values with that. Any Ideas how to track that down? I can also open an Issue at GitHub if you want.

@fork can you please post your (redacted) config for the mqtt_consumer input!? I suspect your topic layout is still the same?

Hey @srebhan ofc.

Layout is still the same. All fields are float except two string fields: “status” and “logger_status”.

[[inputs.mqtt_consumer]]
  servers = ["tcp://mqtt:1883"]
  topics = [
    "WrGiebel/#",
  ]
  topic_tag = "topic"
  client_trace = true
  client_id = "telegrafWr"
  username = "telegraf"
  password = "XXXX"
  insecure_skip_verify = false
  data_format = "value"
  data_type = "auto_float"


@fork are you aware that data_type = "auto_float" only works since 1.28.0 released yesterday!? Or are you using a nightly build?

Hey @srebhan you are absolutely correct I was not using 1.28.0 and were not aware of that it was just released in 1.28.0.
But since I didn’t get any warnings or error messages when I hat it configured in <1.28.0 I was at a state that it was implemented in the version.

tl;dr, Works now but one of my Datapoints seems to be float already and auto_float seems to try to put it in as string and Influx is throwing an error now because of that.
Had to figure that out…

Yeah the issue is that I checked the value only with the new feature. Before it just silently ignored all mistypes data_type values… :frowning:

For the column type being already float: There is nothing we can do about it as InfluxDB only accepts one data-type per field in a series.