influxdata / telegraf

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

OPCUA - Access session timeout parameter from Telegraf #15258

Closed maxime-jolliet-airseas closed 5 months ago

maxime-jolliet-airseas commented 5 months ago

Use Case

Telegraf uses default session configuration parameters from gopcua, as defined here : https://github.com/gopcua/opcua/blob/main/config.go#L40

Namely, the session timeout is set to 20 minutes. I connect to PLC that have only a few PCUA session slots available (typically, 5 to 10). Often, I max out the session slots (I do not know why), and end up with a "BadTooManySessionError" - and have to wait for the 20 minutes timout to expire.

Expected behavior

I'd like to add a parameter to Telegraf OPCUA plugins configuration "session_timeout".

  ## Maximum time a session can be inactive. The server will kill these sesion, if the client has died or is no longer connected to the server .
  connect_timeout = "20s"

Actual behavior

I am not aware of any workaround, sadly.

Additional info

I don't know Go, but I can try to start a PR, if that's OK.

powersj commented 5 months ago

Hi,

Happy to see a PR with this config option exposed. I believe you would want to look at plugins/common/opcua/client.go and expose a SessionTimeout variable called session_timeout in the TOML config.

Then in plugins/common/opcua/opcua_util.go, in the generateClientOpts function, set the timeout option.

Finally, update the sample.conf and README.md with the new option you have added.