fix(inputs.s7comm): Allow PDU-size to be set as config option (#14045)

This commit is contained in:
phagemann 2023-10-04 09:59:44 +02:00 committed by GitHub
parent 4759214471
commit 30bbf4fb62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -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"

View File

@ -25,7 +25,6 @@ import (
//go:embed sample.conf
var sampleConfig string
const maxRequestsPerBatch = 20
const addressRegexp = `^(?P<area>[A-Z]+)(?P<no>[0-9]+)\.(?P<type>[A-Z]+)(?P<start>[0-9]+)(?:\.(?P<extra>.*))?$`
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),
}
})
}

View File

@ -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"