influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

Parallelism / RTU over TCP #14528

Closed Ogy closed 10 months ago

Ogy commented 10 months ago

Relevant telegraf.conf

[[inputs.exec]]
  data_format = "json"
  commands = [
    "systemctl start socat@1",
    "sleep 2s"
  ]
  timeout = "10s"

[[inputs.modbus]]
  name = "modbus1"
  slave_id = 1
  timeout = "2s"
  controller = "file:///socat/1"
  configuration_type = "register"
 baud_rate = 9600
 data_bits = 8
 parity = "N"
 stop_bits = 1

discrete_inputs = [
  { name = "DI1", address = [0]},
]

[[inputs.exec]]
  data_format = "json"
  commands = [
    "systemctl stop socat@1",
    "sleep 1"
  ]
  timeout = "2s"

Logs from Telegraf

2024-01-05T00:40:23Z E! [inputs.modbus] Error in plugin: no such file or directory
2024-01-05T00:40:23Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command "systemctl stop socat@1": Job for socat@1.service canceled.

System info

Telegraf 1.29.1 (git: HEAD@9a469977)

Docker

No response

Steps to reproduce

run multiple exec

Expected behavior

working

Actual behavior

doesn't work

Additional info

Hello, I was not able to run Modbus RTU over TCP. I gave it up, as, in my humble opinion, it's not implemented or I'm dumb. I came up with a socat workaround, which works well. Unfortunately, I have more readers, so I must close socat after reading data.

The questions are:

Is RTU over TCP implemented? Can jobs in one configuration be run sequentially, not in parallel? Can jobs be set to run even if one fails? (e.g., Modbus doesn't have a PTY - fails, and the last job (kill socat) is canceled) Are there any pre / post actions?

Many thanks in advance

srebhan commented 10 months ago

@Ogy plugins are executed in parallel in Telegraf, so your config will never work as you cannot predict the order of execution.

This being said, ModbusTCP with RTU is definitively implemented (I'm using this here right now)! So let's try to fix this the right way... ;-) How is your device connected? Does it actually speak ModbusTCP or is this a ethernet-to-serial converter that just passes through the data to the serial bus? In this case you would need to specify this with transmission_mode = "RTUoverTCP" because this is different from ModbusTCP.

An error message and/or your socat config might help to find out what to do... Furthermore, let's start with getting this to run with a single device - single request first (e.g. run telegraf ... --test --debug) and then narrow down the "multiple devices" path...

Ogy commented 10 months ago

Wow, many thanks! I'm blind, I overlooked the option 'transmission_mode=RTUoverTCP.' Now it's much simpler :D. It works as it should. Thanks again, and sorry for bothering you.

Ogy commented 10 months ago

Thanks for info!

srebhan commented 10 months ago

You are welcome. And no worries, that's what I'm here for. ;-)