From 7019c7008eab679912c7d207cb7383f9ab155c48 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 29 Jan 2024 13:42:02 +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..c541ce084 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.ullTotalVirtual, + VirtualAvail: memInfo.ullAvailVirtual, } ret.Used = ret.Total - ret.Available