From 9e8f6bc3bdb4518c9437d2c66f8c87bf45d62838 Mon Sep 17 00:00:00 2001 From: Alex K <8418476+fearful-symmetry@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:57:17 -0700 Subject: [PATCH] fix diskio and memory bugs under windows (#21992) (#22000) (cherry picked from commit 6955665227cb13504c52a01d3cbccd0a28c7ed9e) --- metricbeat/module/system/diskio/diskio.go | 3 ++- metricbeat/module/system/memory/memory.go | 6 +++--- metricbeat/module/system/process/process.go | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/metricbeat/module/system/diskio/diskio.go b/metricbeat/module/system/diskio/diskio.go index 1359180cff6..4a7e2e2b5fe 100644 --- a/metricbeat/module/system/diskio/diskio.go +++ b/metricbeat/module/system/diskio/diskio.go @@ -21,6 +21,7 @@ package diskio import ( "fmt" + "runtime" "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/metric/system/diskio" @@ -114,7 +115,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { diskWriteBytes += counters.WriteBytes //Add linux-only data if agent is off as not to make breaking changes. - if !m.IsAgent { + if !m.IsAgent && runtime.GOOS == "linux" { result, err := m.statistics.CalcIOStatistics(counters) if err != nil { return errors.Wrap(err, "error calculating iostat") diff --git a/metricbeat/module/system/memory/memory.go b/metricbeat/module/system/memory/memory.go index 27e76b85489..26c6bea1867 100644 --- a/metricbeat/module/system/memory/memory.go +++ b/metricbeat/module/system/memory/memory.go @@ -42,7 +42,7 @@ func init() { // MetricSet for fetching system memory metrics. type MetricSet struct { mb.BaseMetricSet - IsFleet bool + IsAgent bool } // New is a mb.MetricSetFactory that returns a memory.MetricSet. @@ -53,7 +53,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return nil, fmt.Errorf("unexpected module type") } - return &MetricSet{BaseMetricSet: base, IsFleet: systemModule.IsAgent}, nil + return &MetricSet{BaseMetricSet: base, IsAgent: systemModule.IsAgent}, nil } // Fetch fetches memory metrics from the OS. @@ -117,7 +117,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { } // for backwards compatibility, only report if we're not in fleet mode - if !m.IsFleet { + if !m.IsAgent { err := linux.FetchLinuxMemStats(memory) if err != nil { return errors.Wrap(err, "error getting page stats") diff --git a/metricbeat/module/system/process/process.go b/metricbeat/module/system/process/process.go index 804c62d06d6..c99ffaa1123 100644 --- a/metricbeat/module/system/process/process.go +++ b/metricbeat/module/system/process/process.go @@ -156,10 +156,12 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { // There's some more Windows memory quirks we need to deal with. // "rss" is a linux concept, but "wss" is a direct match on Windows. // "share" is also unavailable on Windows. + if runtime.GOOS == "windows" { + proc.Delete("memory.share") + } if m.IsAgent { if runtime.GOOS == "windows" { - proc.Delete("memory.share") if setSize := getAndRemove(proc, "memory.rss"); setSize != nil { proc.Put("memory.wss", setSize) }