Skip to content

Commit

Permalink
fix diskio and memory bugs under windows (#21992) (#21999)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6955665)
  • Loading branch information
fearful-symmetry committed Oct 20, 2020
1 parent 2c54a6a commit 87dc4fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion metricbeat/module/system/diskio/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 87dc4fe

Please sign in to comment.