Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume all swap memory is free on values overflow #9383

Merged
merged 4 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
12 changes: 12 additions & 0 deletions libbeat/metric/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package memory

import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
sigar "github.com/elastic/gosigar"
)

Expand Down Expand Up @@ -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 {
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
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
}

Expand Down