diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c1b5f38c0455..bc08934348e8 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -38,6 +38,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d - Fix autodiscover configurations stopping when metadata is missing. {pull}8851[8851] - Log events at the debug level when dropped by encoding problems. {pull}9251[9251] - Refresh host metadata in add_host_metadata. {pull}9359[9359] +- When collecting swap metrics for beats telemetry or system metricbeat module handle cases of free swap being bigger than total swap by assuming no swap is being used. {issue}6271[6271] {pull}9383[9383] *Auditbeat* diff --git a/libbeat/metric/system/memory/memory.go b/libbeat/metric/system/memory/memory.go index 594fc616c198..585c80d5c743 100644 --- a/libbeat/metric/system/memory/memory.go +++ b/libbeat/metric/system/memory/memory.go @@ -21,6 +21,7 @@ package memory import ( "github.com/elastic/beats/libbeat/common" + "github.com/elastic/beats/libbeat/logp" sigar "github.com/elastic/gosigar" ) @@ -69,6 +70,17 @@ func GetSwap() (*SwapStat, error) { return nil, err } + // This shouldn't happen, but it has been reported to happen and + // this can provoke too big values for used swap. + // Workaround this by assuming that all swap is free in that case. + if swap.Free > swap.Total || swap.Used > swap.Total { + logp.Debug("memory", + "Unexpected values for swap memory - total: %v free: %v used: %v. Setting swap used to 0.", + swap.Total, swap.Free, swap.Used) + swap.Free = swap.Total + swap.Used = 0 + } + return &SwapStat{Swap: swap}, nil }