OutsideIT / FireMotD

:fire: Fire Framework Linux MoTD Generator :fire:
https://outsideit.net/firemotd
GNU General Public License v3.0
175 stars 45 forks source link

Changed to show real memory usage #68

Closed dimon222 closed 7 years ago

dimon222 commented 7 years ago

Basically solution for #57

dimon222 commented 7 years ago

Interesting, it does look significantly different from my Debian output: image

Perhaps, we should use OS dependent solution? Is there example for other platforms by any chance? I pretty much expect same behavior from Ubuntu (like I have), but not sure about the rest distributions.

willemdh commented 7 years ago

Seems good solution to make it os dependant. Just need to check this on a few servers. Got a few opensuse servers too. Might take a week.

willemdh commented 7 years ago

@dimon222 Ok, I found some time to further test this. It still wasn't ok for CentOS / Red Hat. Changed it to this now where I make the sum of buff/cache and used:

    if [[ "$(jq -r ".Release.Value" $ExportFile)" =~ (^CentOS*|^Red*) ]] ; then
        # CentOS based distributions
        MemBuffCacheB="$(free | awk '/Mem:/ { print $6 }')"
        MemFreeUsedB="$(free | awk '/Mem:/ { print $3 }')"
        MemUsedB=$(echo "$MemBuffCacheB+$MemFreeUsedB" | bc)
        MemFreeB="$(free | awk '/Mem:/ { print $4 }')"
    else
        # Debian based distributions and possibly others (?)
        MemFreeB="$(free | grep buffers/cache | awk '{print $4}')"
        MemUsedB="$(free | grep buffers/cache | awk '{print $3}')"
    fi

If you create a new pr with the above I'll accept. Please also change the version number for me. Tx

dimon222 commented 7 years ago

No worries, I added your change and rebased code for cleaner merge of tree.

dimon222 commented 7 years ago

Actually, after small investigation I found out that its not system dependent but rather procps version related. The two-line format is fresh new notation that seem to come beginning version 3.3.10.

Source: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=798994

I updated my changes with check of /usr/bin/free version instead of check of OS distributive (which seem to be unrelated). Can you rerun test? My Debian is working with its 3.3.9 detection.

willemdh commented 7 years ago

Nice find @dimon222 , and nice VersionComparison function. I'll double check asap.

dimon222 commented 7 years ago

Found condition bug, fixed + rebased again. Should be working correctly for you now.