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 <[email protected]>
  • Loading branch information
sni committed Jan 26, 2024
1 parent 65b5fa3 commit 202353d
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.ullAvailVirtual,
VirtualAvail: memInfo.ullAvailExtendedVirtual,
}

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

0 comments on commit 202353d

Please sign in to comment.