feat(inputs.modbus): add config option to pause after connect (#11983)

This commit is contained in:
Joerg Epping 2022-10-18 20:42:18 +02:00 committed by GitHub
parent b1fc5254e5
commit 589447abaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 5 deletions

View File

@ -5970,6 +5970,8 @@
# #
# ## Enable workarounds required by some devices to work correctly # ## Enable workarounds required by some devices to work correctly
# # [inputs.modbus.workarounds] # # [inputs.modbus.workarounds]
# ## Pause after connect delays the first request by the specified time. This might be necessary for (slow) devices.
# # pause_after_connect = "0ms"
# ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. # ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices.
# # pause_between_requests = "0ms" # # pause_between_requests = "0ms"
# ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain # ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain

View File

@ -5764,6 +5764,8 @@
# #
# ## Enable workarounds required by some devices to work correctly # ## Enable workarounds required by some devices to work correctly
# # [inputs.modbus.workarounds] # # [inputs.modbus.workarounds]
# ## Pause after connect delays the first request by the specified time. This might be necessary for (slow) devices.
# # pause_after_connect = "0ms"
# ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. # ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices.
# # pause_between_requests = "0ms" # # pause_between_requests = "0ms"
# ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain # ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain

View File

@ -196,6 +196,8 @@ Registers via Modbus TCP or Modbus RTU/ASCII.
## Enable workarounds required by some devices to work correctly ## Enable workarounds required by some devices to work correctly
# [inputs.modbus.workarounds] # [inputs.modbus.workarounds]
## Pause after connect delays the first request by the specified time. This might be necessary for (slow) devices.
# pause_after_connect = "0ms"
## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices.
# pause_between_requests = "0ms" # pause_between_requests = "0ms"
## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain
@ -211,9 +213,9 @@ those debug messages, Telegraf has to be started with debugging enabled
(i.e. with the `--debug` option). Please be aware that connection tracing will (i.e. with the `--debug` option). Please be aware that connection tracing will
produce a lot of messages and should __NOT__ be used in production environments. produce a lot of messages and should __NOT__ be used in production environments.
Please use `pause_between_requests` with care. Ensure the total gather time, Please use `pause_after_connect` / `pause_between_requests` with care. Ensure
including the pause(s), does not exceed the configured collection interval. Note the total gather time, including the pause(s), does not exceed the configured
that pauses add up if multiple requests are sent! collection interval. Note that pauses add up if multiple requests are sent!
## Configuration styles ## Configuration styles

View File

@ -24,8 +24,9 @@ var sampleConfigStart string
var sampleConfigEnd string var sampleConfigEnd string
type ModbusWorkarounds struct { type ModbusWorkarounds struct {
PollPause config.Duration `toml:"pause_between_requests"` AfterConnectPause config.Duration `toml:"pause_after_connect"`
CloseAfterGather bool `toml:"close_connection_after_gather"` PollPause config.Duration `toml:"pause_between_requests"`
CloseAfterGather bool `toml:"close_connection_after_gather"`
} }
// Modbus holds all data relevant to the plugin // Modbus holds all data relevant to the plugin
@ -265,6 +266,10 @@ func (m *Modbus) initClient() error {
func (m *Modbus) connect() error { func (m *Modbus) connect() error {
err := m.handler.Connect() err := m.handler.Connect()
m.isConnected = err == nil m.isConnected = err == nil
if m.isConnected && m.Workarounds.AfterConnectPause != 0 {
nextRequest := time.Now().Add(time.Duration(m.Workarounds.AfterConnectPause))
time.Sleep(time.Until(nextRequest))
}
return err return err
} }

View File

@ -188,6 +188,8 @@
## Enable workarounds required by some devices to work correctly ## Enable workarounds required by some devices to work correctly
# [inputs.modbus.workarounds] # [inputs.modbus.workarounds]
## Pause after connect delays the first request by the specified time. This might be necessary for (slow) devices.
# pause_after_connect = "0ms"
## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices.
# pause_between_requests = "0ms" # pause_between_requests = "0ms"
## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain

View File

@ -1,5 +1,7 @@
## Enable workarounds required by some devices to work correctly ## Enable workarounds required by some devices to work correctly
# [inputs.modbus.workarounds] # [inputs.modbus.workarounds]
## Pause after connect delays the first request by the specified time. This might be necessary for (slow) devices.
# pause_after_connect = "0ms"
## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices.
# pause_between_requests = "0ms" # pause_between_requests = "0ms"
## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain