From bd50f74b37e37a4a071db1c5a5593023d6cae573 Mon Sep 17 00:00:00 2001 From: BourneID Date: Thu, 25 Oct 2018 23:36:16 +0100 Subject: [PATCH] Add check for MemAvailable and calculations if it does not exist. --- lgsm/functions/info_distro.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lgsm/functions/info_distro.sh b/lgsm/functions/info_distro.sh index 71e3aa33c..ac56fa233 100644 --- a/lgsm/functions/info_distro.sh +++ b/lgsm/functions/info_distro.sh @@ -91,6 +91,28 @@ load=$(uptime|awk -F 'load average: ' '{ print $2 }') ## Memory information +# Issue #2005 - Kernel 3.14+ contains MemAvailable which should be used. All others will be calculated + +# define the following as integers due to AWK string issues +declare -i physmemtotalkb +declare -i physmemfreekb +declare -i physmembufferskb +declare -i physmemcachedkb +declare -i physmemactualfreekb + +# get the raw KB values of these fields +physmemtotalkb=$(grep MemTotal /proc/meminfo | awk '{print $2}') +physmemfreekb=$(grep ^MemFree /proc/meminfo | awk '{print $2}') +physmembufferskb=$(grep ^Buffers /proc/meminfo | awk '{print $2}') +physmemcachedkb=$(grep ^Cached /proc/meminfo | awk '{print $2}') + +# check if MemAvailable Exists +if grep -q ^MemAvailable /proc/meminfo; then +physmemactualfreekb=$(grep ^MemAvailable /proc/meminfo | awk '{print $2}') +else +physmemactualfreekb=${physmemfreekb}+${physmembufferskb}+${physmemcachedkb} +fi + # Available RAM and swap. physmemtotalmb=$(($(grep MemTotal /proc/meminfo | awk '{print $2}')/1024)) physmemtotal=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemTotal /proc/meminfo | awk '{print $2}')K")