elastic / elastic-agent-system-metrics

Apache License 2.0
0 stars 22 forks source link

[metric/memory] use of wrong source for Windows swap calculations #130

Open leehinman opened 4 months ago

leehinman commented 4 months ago

currently the windows memory module uses GlobalMemoryStatusEx to get the swap Total, Used & FreeBytes.

https://github.com/elastic/elastic-agent-system-metrics/blob/5c1fcf28d051e7683e31e20b5dce97c97f144c4f/metric/memory/memory_windows.go#L33-L49

But GlobalMemoryStatusEx is really a syscall of procGlobalMemoryStatusEx which ends up being procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")

And the documentation for MemoryStatusEx says that we should be using GetPerformanceInfo instead.

ullTotalPageFile

The current committed memory limit for the system or the current process, whichever is smaller, in bytes. To get the system-wide committed memory limit, call GetPerformanceInfo.

ullAvailPageFile

The maximum amount of memory the current process can commit, in bytes. This value is equal to or smaller than the system-wide available commit value. To calculate the system-wide available commit value, call GetPerformanceInfo and subtract the value of CommitTotal from the value of CommitLimit.

This can lead to Metricbeat showing an incorrect amount of swap, especially when swap is configured to be very small or zero.