From e148d6cf8db31861ae4daa835e209d3e93c7c967 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Tue, 23 Apr 2024 18:00:06 +0100 Subject: [PATCH] fix(inputs.sysstat): Prevent default sadc_interval from increasing on reload (#15212) --- plugins/inputs/sysstat/sysstat.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 177e632c0..834e94513 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -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) } }