Skip to content

Commit

Permalink
memory: expose virtual totals / avail values on windows
Browse files Browse the repository at this point in the history
There are 2 more memory values i'd like to use. They are there
already, just not exposed by the module.

- https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex

Signed-off-by: Sven Nierlein <sven@consol.de>
  • Loading branch information
sni committed Jan 29, 2024
1 parent 65b5fa3 commit 7019c70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ type VirtualMemoryStat struct {
HugePagesSurp uint64 `json:"hugePagesSurp"`
HugePageSize uint64 `json:"hugePageSize"`
AnonHugePages uint64 `json:"anonHugePages"`

// Windows specific numbers
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
VirtualTotal uint64 `json:"virtualTotal"`
VirtualAvail uint64 `json:"virtualAvail"`
}

type SwapMemoryStat struct {
Expand Down
10 changes: 6 additions & 4 deletions mem/mem_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
}

ret := &VirtualMemoryStat{
Total: memInfo.ullTotalPhys,
Available: memInfo.ullAvailPhys,
Free: memInfo.ullAvailPhys,
UsedPercent: float64(memInfo.dwMemoryLoad),
Total: memInfo.ullTotalPhys,
Available: memInfo.ullAvailPhys,
Free: memInfo.ullAvailPhys,
UsedPercent: float64(memInfo.dwMemoryLoad),
VirtualTotal: memInfo.ullTotalVirtual,
VirtualAvail: memInfo.ullAvailVirtual,
}

ret.Used = ret.Total - ret.Available
Expand Down

0 comments on commit 7019c70

Please # to comment.