]> granicus.if.org Git - icinga2/commitdiff
Fix: check_memory tool shows incorrect memory size on windows
authorPaul Richards <paul@minimoo.org>
Sun, 1 Mar 2015 21:23:36 +0000 (21:23 +0000)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 1 Mar 2015 21:29:54 +0000 (22:29 +0100)
On a PC with >4GB of RAM, check_memory utility returns
an incorrect amount of RAM:

MEMORY OK - 100% free | memory=4096MB;;;0;4096

This patch uses GlobalMemoryStatusEx instead of GlobalMemoryStatus
[https://msdn.microsoft.com/en-us/library/windows/desktop/aa366586%28v=vs.85%29.aspx]

Following patch output of check_memory is as follows:

MEMORY OK - 32.4873% free | memory=5312MB;;;0;16351

fixes #8559

Signed-off-by: Gunnar Beutner <gunnar@beutner.name>
plugins/check_memory.cpp

index 1d30f367353f58506432b96c67153399394211d3..229d5243c51449701dd6ed402c251523521a1323 100644 (file)
@@ -36,7 +36,7 @@ static BOOL debug = FALSE;
 struct printInfoStruct
 {
        threshold warn, crit;
-       DWORD tRam, aRam;
+       DWORDLONG tRam, aRam;
        Bunit unit = BunitMB;
 };
 
@@ -213,16 +213,18 @@ int check_memory(printInfoStruct& printInfo)
        if (debug)
                wcout << L"Accessing memory statistics via MemoryStatus" << endl;
 
-       _MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS;
+       _MEMORYSTATUSEX *pMemBuf = new _MEMORYSTATUSEX;
 
-       GlobalMemoryStatus(pMemBuf);
+       pMemBuf->dwLength = sizeof(*pMemBuf);
 
-       printInfo.tRam = round(pMemBuf->dwTotalPhys / pow(1024.0, printInfo.unit));
-       printInfo.aRam = round(pMemBuf->dwAvailPhys / pow(1024.0, printInfo.unit));
+       GlobalMemoryStatusEx(pMemBuf);
+
+       printInfo.tRam = round(pMemBuf->ullTotalPhys / pow(1024.0, printInfo.unit));
+       printInfo.aRam = round(pMemBuf->ullAvailPhys / pow(1024.0, printInfo.unit));
 
        if (debug)
-               wcout << L"Found pMemBuf->dwTotalPhys: " << pMemBuf->dwTotalPhys << endl
-               << L"Found pMemBuf->dwAvailPhys: " << pMemBuf->dwAvailPhys << endl;
+               wcout << L"Found pMemBuf->dwTotalPhys: " << pMemBuf->ullTotalPhys << endl
+               << L"Found pMemBuf->dwAvailPhys: " << pMemBuf->ullAvailPhys << endl;
 
        delete pMemBuf;