Skip to content

Commit

Permalink
Fix for GameServerManagers#2005 to look for MemAvailable, use if exis…
Browse files Browse the repository at this point in the history
…ts otherwise calculate it
  • Loading branch information
Bourne-ID committed Oct 26, 2018
1 parent 0707094 commit c06b381
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions lgsm/functions/info_distro.sh
Expand Up @@ -93,38 +93,27 @@ load=$(uptime|awk -F 'load average: ' '{ print $2 }')

# 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}')
physmemreclaimablekb=$(grep ^SReclaimable /proc/meminfo | awk '{print $2}')

# check if MemAvailable Exists
if grep -q ^MemAvailable /proc/meminfo; then
physmemactualfreekb=$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')
physmemactualfreekb=$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')
else
physmemactualfreekb=${physmemfreekb}+${physmembufferskb}+${physmemcachedkb}
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")
physmemfree=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')K")
physmemused=$(numfmt --to=iec --from=iec --suffix=B "$(($(grep "^MemTotal\:" /proc/meminfo | awk '{print $2}')-$(grep "^MemFree\:" /proc/meminfo | awk '{print $2}')-$(grep "^Buffers\:" /proc/meminfo | awk '{print $2}')-$(grep "^Cached\:" /proc/meminfo | awk '{print $2}')-$(grep "^SReclaimable\:" /proc/meminfo | awk '{print $2}')))K")
{ # try
physmemavailable=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^MemAvailable /proc/meminfo | awk '{print $2}')K")
physmemcached=$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^Cached /proc/meminfo | awk '{print $2}')+$(grep "^SReclaimable\:" /proc/meminfo | awk '{print $2}')))K")
} 2>/dev/null || { # fail silently, catch
physmemavailable="n/a"
physmemcached="n/a"
}
physmemtotalmb=$((${physmemtotalkb}/1024))
physmemtotal=$(numfmt --to=iec --from=iec --suffix=B "${physmemtotalkb}K")
physmemfree=$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")
physmemused=$(numfmt --to=iec --from=iec --suffix=B "$((${physmemtotalkb}-${physmemfreekb}-${physmembufferskb}-${physmemcachedkb}-${physmemreclaimablekb}))K")
physmemavailable=$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")
physmemcached=$(numfmt --to=iec --from=iec --suffix=B "$((${physmemcachedkb}+${physmemreclaimablekb}))K")

swaptotal=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapTotal /proc/meminfo | awk '{print $2}')K")
swapfree=$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapFree /proc/meminfo | awk '{print $2}')K")
Expand Down

0 comments on commit c06b381

Please sign in to comment.