From 30bbf4fb621b75ad088f09cdd54fa32e77309828 Mon Sep 17 00:00:00 2001 From: phagemann Date: Wed, 4 Oct 2023 09:59:44 +0200 Subject: [PATCH] fix(inputs.s7comm): Allow PDU-size to be set as config option (#14045) --- plugins/inputs/s7comm/README.md | 3 +++ plugins/inputs/s7comm/s7comm.go | 11 ++++++----- plugins/inputs/s7comm/sample.conf | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/s7comm/README.md b/plugins/inputs/s7comm/README.md index 2f6f1893a..b29c3b907 100644 --- a/plugins/inputs/s7comm/README.md +++ b/plugins/inputs/s7comm/README.md @@ -23,6 +23,9 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. rack = 0 slot = 0 + ## Max count of fields to be bundled in one batch-request. (PDU size) + # pdu_size = 20 + ## Timeout for requests # timeout = "10s" diff --git a/plugins/inputs/s7comm/s7comm.go b/plugins/inputs/s7comm/s7comm.go index 93a601a8b..bbfcee38b 100644 --- a/plugins/inputs/s7comm/s7comm.go +++ b/plugins/inputs/s7comm/s7comm.go @@ -25,7 +25,6 @@ import ( //go:embed sample.conf var sampleConfig string -const maxRequestsPerBatch = 20 const addressRegexp = `^(?P[A-Z]+)(?P[0-9]+)\.(?P[A-Z]+)(?P[0-9]+)(?:\.(?P.*))?$` var ( @@ -85,6 +84,7 @@ type S7comm struct { Server string `toml:"server"` Rack int `toml:"rack"` Slot int `toml:"slot"` + BatchMaxSize int `toml:"pdu_size"` Timeout config.Duration `toml:"timeout"` DebugConnection bool `toml:"debug_connection"` Configs []metricDefinition `toml:"metric"` @@ -223,7 +223,7 @@ func (s *S7comm) createRequests() error { current.mappings = append(current.mappings, m) // If the batch is full, start a new one - if len(current.items) == maxRequestsPerBatch { + if len(current.items) == s.BatchMaxSize { s.batches = append(s.batches, current) current = batch{} } @@ -402,9 +402,10 @@ func fieldID(seed maphash.Seed, def metricDefinition, field metricFieldDefinitio func init() { inputs.Add("s7comm", func() telegraf.Input { return &S7comm{ - Rack: -1, - Slot: -1, - Timeout: config.Duration(10 * time.Second), + Rack: -1, + Slot: -1, + BatchMaxSize: 20, + Timeout: config.Duration(10 * time.Second), } }) } diff --git a/plugins/inputs/s7comm/sample.conf b/plugins/inputs/s7comm/sample.conf index 62f66788c..42d3eb0bd 100644 --- a/plugins/inputs/s7comm/sample.conf +++ b/plugins/inputs/s7comm/sample.conf @@ -7,6 +7,9 @@ rack = 0 slot = 0 + ## Max count of fields to be bundled in one batch-request. (PDU size) + # pdu_size = 20 + ## Timeout for requests # timeout = "10s"