Bug #3349
Updated by Chris Buechler over 10 years ago
I have 2048MB on my system. With the code below the web gui system information widget shows i have 512MB installed, the code is in the functions.inc.php file. <pre> function mem_usage() { $memory = ""; exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " . "vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory); $totalMem = $memory[0]; $availMem = $memory[1] + $memory[2] + $memory[3]; $usedMem = $totalMem - $availMem; $memUsage = round(($usedMem * 100) / $totalMem,0); return $memUsage; </pre> I took a look at the math and the sysctl commands used. I re-coded the math and also switched the commands to use the one that pulls the actual memory allocated by the system which is the same command that is pulling the total memory right next to the used % on the system information widget. <pre> function mem_usage() { $memory = ""; exec("/sbin/sysctl -n vm.stats.vm.v_free_count hw.physmem hw.pagesize", $memory); $totalMem = $memory[1]; $availMem = $memory[0] * $memory[2]; $usedMem = $totalMem - $availMem; $memUsage = round(($usedMem * 100) / $totalMem, 2); return $memUsage; </pre>