Project

General

Profile

Actions

Bug #3349

closed

System Information Widget Showing Incorrect Memory Used %

Added by Wifi Ghost almost 12 years ago. Updated over 9 years ago.

Status:
Not a Bug
Priority:
Normal
Assignee:
-
Category:
Web Interface
Target version:
-
Start date:
11/27/2013
Due date:
% Done:

0%

Estimated time:
Plus Target Version:
Release Notes:
Affected Version:
Affected Architecture:

Description

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.

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;

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.

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;
Actions

Also available in: Atom PDF