From 202353d6a961e199b598cc9602f7b34c365381b4 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Fri, 26 Jan 2024 15:46:35 +0100 Subject: [PATCH] memory: expose virtual totals / avail values on windows 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 --- mem/mem.go | 5 +++++ mem/mem_windows.go | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mem/mem.go b/mem/mem.go index edaf268bb..9402d27be 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -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 { diff --git a/mem/mem_windows.go b/mem/mem_windows.go index 8c7fb1a13..a491c138f 100644 --- a/mem/mem_windows.go +++ b/mem/mem_windows.go @@ -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