From fb6f6a4daaa567225c443e43cf66a14072ce45f3 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Mon, 2 May 2022 16:57:19 +0200 Subject: [PATCH] Fix GPFS collector last state handling --- collectors/gpfsMetric.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/collectors/gpfsMetric.go b/collectors/gpfsMetric.go index 26fc723..ed63201 100644 --- a/collectors/gpfsMetric.go +++ b/collectors/gpfsMetric.go @@ -70,6 +70,7 @@ func (m *GpfsCollector) Init(config json.RawMessage) error { for _, fs := range m.config.ExcludeFilesystem { m.skipFS[fs] = struct{}{} } + m.lastState = make(map[string]GpfsCollectorLastState) // GPFS / IBM Spectrum Scale file system statistics can only be queried by user root user, err := user.Current() @@ -162,11 +163,16 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) { continue } + // Add filesystem tag m.tags["filesystem"] = filesystem - if _, ok := m.lastState[filesystem]; !ok { - m.lastState[filesystem] = GpfsCollectorLastState{ - bytesRead: -1, - bytesWritten: -1, + + // Create initial last state + if m.config.SendBandwidths { + if _, ok := m.lastState[filesystem]; !ok { + m.lastState[filesystem] = GpfsCollectorLastState{ + bytesRead: -1, + bytesWritten: -1, + } } }