fix(inputs.sysstat): Prevent default sadc_interval from increasing on reload (#15212)

This commit is contained in:
Nick Thomas 2024-04-23 18:00:06 +01:00 committed by GitHub
parent 5c483dc3a9
commit e148d6cf8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 5 deletions

View File

@ -27,7 +27,6 @@ import (
var sampleConfig string
var (
firstTimestamp time.Time
execCommand = exec.Command // execCommand is used to mock commands in tests.
dfltActivities = []string{"DISK"}
)
@ -70,9 +69,12 @@ type Sysstat struct {
// DeviceTags adds the possibility to add additional tags for devices.
DeviceTags map[string][]map[string]string `toml:"device_tags"`
interval int
Log telegraf.Logger
// Used to autodetect how long the sadc command should run for
interval int
firstTimestamp time.Time
}
const cmd = "sadf"
@ -105,10 +107,10 @@ func (s *Sysstat) Gather(acc telegraf.Accumulator) error {
}
if s.interval == 0 {
if firstTimestamp.IsZero() {
firstTimestamp = time.Now()
if s.firstTimestamp.IsZero() {
s.firstTimestamp = time.Now()
} else {
s.interval = int(time.Since(firstTimestamp).Seconds() + 0.5)
s.interval = int(time.Since(s.firstTimestamp).Seconds() + 0.5)
}
}