|
|
@ -21,84 +21,87 @@ fi |
|
|
|
|
|
|
|
## Distro |
|
|
|
# Returns architecture, kernel and distro/os. |
|
|
|
arch="$(uname -m)" |
|
|
|
kernel="$(uname -r)" |
|
|
|
|
|
|
|
# Distro Name - Ubuntu 16.04 LTS |
|
|
|
# Distro Version - 16.04 |
|
|
|
# Distro ID - ubuntu |
|
|
|
# Distro Codename - xenial |
|
|
|
arch="$(uname -m)" # Architecture e.g. x86_64 |
|
|
|
kernel="$(uname -r)" # Kernel e.g. 2.6.32-042stab120.16 |
|
|
|
|
|
|
|
# Gathers distro info from various sources filling in missing gaps. |
|
|
|
distro_info_array=(os-release lsb_release hostnamectl debian_version redhat-release) |
|
|
|
for distro_info in "${distro_info_array[@]}"; do |
|
|
|
if [ -f "/etc/os-release" ] && [ "${distro_info}" == "os-release" ]; then |
|
|
|
distroname="$(grep "PRETTY_NAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" |
|
|
|
distroversion="$(grep "VERSION_ID" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" |
|
|
|
# Special var for rhel like distros to removed point in number e.g 8.4 to just 8. |
|
|
|
distroversionrh="$(sed -nr 's/^VERSION_ID="([0-9]*).+?"/\1/p' /etc/os-release)" |
|
|
|
distroid="$(grep "ID=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" |
|
|
|
distroidlike="$(grep "ID_LIKE=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" |
|
|
|
distrocodename="$(grep "VERSION_CODENAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" |
|
|
|
distroname="$(grep "PRETTY_NAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. Ubuntu 22.04.3 LTS |
|
|
|
distroversion="$(grep "VERSION_ID" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. 22.04 |
|
|
|
# Special var for rhel like distros to remove point in number e.g 8.4 to just 8. |
|
|
|
if [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then |
|
|
|
distroversionrh="$(sed -nr 's/^VERSION_ID="([0-9]*).+?"/\1/p' /etc/os-release)" # e.g. 8 |
|
|
|
fi |
|
|
|
distroid="$(grep "ID=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. ubuntu |
|
|
|
distroidlike="$(grep "ID_LIKE=" /etc/os-release | grep -v _ID | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. debian |
|
|
|
distrocodename="$(grep "VERSION_CODENAME" /etc/os-release | awk -F\= '{gsub(/"/,"",$2);print $2}')" # e.g. jammy |
|
|
|
elif [ "$(command -v lsb_release 2> /dev/null)" ] && [ "${distro_info}" == "lsb_release" ]; then |
|
|
|
if [ -z "${distroname}" ]; then |
|
|
|
distroname="$(lsb_release -sd)" |
|
|
|
distroname="$(lsb_release -sd)" # e.g. Ubuntu 22.04.3 LTS |
|
|
|
elif [ -z "${distroversion}" ]; then |
|
|
|
distroversion="$(lsb_release -sr)" |
|
|
|
distroversion="$(lsb_release -sr)" # e.g. 22.04 |
|
|
|
elif [ -z "${distroid}" ]; then |
|
|
|
distroid="$(lsb_release -si)" |
|
|
|
distroid="$(lsb_release -si)" # e.g. Ubuntu |
|
|
|
elif [ -z "${distrocodename}" ]; then |
|
|
|
distrocodename="$(lsb_release -sc)" |
|
|
|
distrocodename="$(lsb_release -sc)" # e.g. jammy |
|
|
|
fi |
|
|
|
elif [ "$(command -v hostnamectl 2> /dev/null)" ] && [ "${distro_info}" == "hostnamectl" ]; then |
|
|
|
if [ -z "${distroname}" ]; then |
|
|
|
distroname="$(hostnamectl | grep "Operating System" | sed 's/Operating System: //g')" |
|
|
|
distroname="$(hostnamectl | grep "Operating System" | sed 's/Operating System: //g')" # e.g. Ubuntu 22.04.3 LTS |
|
|
|
fi |
|
|
|
elif [ -f "/etc/debian_version" ] && [ "${distro_info}" == "debian_version" ]; then |
|
|
|
if [ -z "${distroname}" ]; then |
|
|
|
distroname="Debian $(cat /etc/debian_version)" |
|
|
|
distroname="Debian $(cat /etc/debian_version)" # e.g. Debian bookworm/sid |
|
|
|
elif [ -z "${distroversion}" ]; then |
|
|
|
distroversion="$(cat /etc/debian_version)" |
|
|
|
distroversion="$(cat /etc/debian_version)" # e.g. bookworm/sid |
|
|
|
elif [ -z "${distroid}" ]; then |
|
|
|
distroid="debian" |
|
|
|
fi |
|
|
|
elif [ -f "/etc/redhat-release" ] && [ "${distro_info}" == "redhat-release" ]; then |
|
|
|
if [ -z "${distroname}" ]; then |
|
|
|
distroname="$(cat /etc/redhat-release)" |
|
|
|
distroname="$(cat /etc/redhat-release)" # e.g. Rocky Linux release 9.2 (Blue Onyx) |
|
|
|
elif [ -z "${distroversion}" ]; then |
|
|
|
distroversion="$(rpm -qa \*-release | grep -Ei "oracle|redhat|centos|fedora" | cut -d"-" -f3)" |
|
|
|
distroversion="$(rpm -qa \*-release | grep -Ei "oracle|redhat|centos|fedora|rocky|alma" | cut -d"-" -f3)" # e.g. 9.2 |
|
|
|
elif [ -z "${distroid}" ]; then |
|
|
|
distroid="$(awk '{print $1}' /etc/redhat-release)" |
|
|
|
distroid="$(awk '{print $1}' /etc/redhat-release)" # e.g. Rocky |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
# Get virtual environment type. |
|
|
|
if [ "$(command -v systemd-detect-virt 2> /dev/null)" ]; then |
|
|
|
virtualenvironment="$(systemd-detect-virt)" |
|
|
|
virtualenvironment="$(systemd-detect-virt)" # e.g. kvm |
|
|
|
fi |
|
|
|
|
|
|
|
# Some RHEL based distros use 8.4 instead of just 8. |
|
|
|
if [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then |
|
|
|
distroversioncsv="${distroversionrh}" |
|
|
|
# distroversioncsv is used for selecting the correct distro csv in data directory |
|
|
|
if [ -n "${distroversionrh}" ]; then |
|
|
|
distroversioncsv="${distroversionrh}" # e.g. 8 |
|
|
|
else |
|
|
|
distroversioncsv="${distroversion}" |
|
|
|
distroversioncsv="${distroversion}" # e.g. 22.04 |
|
|
|
fi |
|
|
|
|
|
|
|
# Check if distro supported by distro vendor. |
|
|
|
# distro-info available in debian based distros. |
|
|
|
if [ "$(command -v distro-info 2> /dev/null)" ]; then |
|
|
|
distrosunsupported="$(distro-info --unsupported)" |
|
|
|
distrosunsupported_array=("${distrosunsupported}") |
|
|
|
for distrounsupported in "${distrosunsupported_array[@]}"; do |
|
|
|
if [ "${distrounsupported}" == "${distrocodename}" ]; then |
|
|
|
distrosupport=unsupported |
|
|
|
distrosupport="unsupported" |
|
|
|
break |
|
|
|
else |
|
|
|
distrosupport=supported |
|
|
|
distrosupport="supported" |
|
|
|
fi |
|
|
|
done |
|
|
|
elif [[ "${distroidlike}" == *"rhel"* ]] || [ "${distroid}" == "rhel" ]; then |
|
|
|
# RHEL/CentOS 7 EOL 2024-06-30. Will be unsupported after this date. |
|
|
|
if [ "${distroversionrh}" -lt "8" ] && [ "$(date +%s)" -lt "1719705600" ]; then |
|
|
|
distrosupport="unsupported" |
|
|
|
else |
|
|
|
distrosupport=unknown |
|
|
|
distrosupport="supported" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
## Glibc version |
|
|
@ -161,36 +164,35 @@ if [ "$(command -v numfmt 2> /dev/null)" ]; then |
|
|
|
# Issue #2005 - Kernel 3.14+ contains MemAvailable which should be used. All others will be calculated. |
|
|
|
|
|
|
|
# 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}')" |
|
|
|
physmemtotalkb="$(grep MemTotal /proc/meminfo | awk '{print $2}')" # integer |
|
|
|
physmemfreekb="$(grep ^MemFree /proc/meminfo | awk '{print $2}')" # integer |
|
|
|
physmembufferskb="$(grep ^Buffers /proc/meminfo | awk '{print $2}')" # integer |
|
|
|
physmemcachedkb="$(grep ^Cached /proc/meminfo | awk '{print $2}')" # integer |
|
|
|
physmemreclaimablekb="$(grep ^SReclaimable /proc/meminfo | awk '{print $2}')" # integer |
|
|
|
|
|
|
|
# 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}')" # integer |
|
|
|
else |
|
|
|
physmemactualfreekb="$((physmemfreekb + physmembufferskb + physmemcachedkb))" |
|
|
|
physmemactualfreekb="$((physmemfreekb + physmembufferskb + physmemcachedkb))" # integer |
|
|
|
fi |
|
|
|
|
|
|
|
# Available RAM and swap. |
|
|
|
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")" |
|
|
|
swapused="$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^SwapTotal /proc/meminfo | awk '{print $2}') - $(grep ^SwapFree /proc/meminfo | awk '{print $2}')))K")" |
|
|
|
physmemtotalmb="$(((physmemtotalkb + 512) / 1024))" # integer |
|
|
|
physmemtotalgb="$(((physmemtotalmb + 512) / 1024))" # integer |
|
|
|
physmemtotal="$(numfmt --to=iec --from=iec --suffix=B "${physmemtotalkb}K")" # string |
|
|
|
physmemfree="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" # string |
|
|
|
physmemused="$(numfmt --to=iec --from=iec --suffix=B "$((physmemtotalkb - physmemfreekb - physmembufferskb - physmemcachedkb - physmemreclaimablekb))K")" # string |
|
|
|
physmemavailable="$(numfmt --to=iec --from=iec --suffix=B "${physmemactualfreekb}K")" # string |
|
|
|
physmemcached="$(numfmt --to=iec --from=iec --suffix=B "$((physmemcachedkb + physmemreclaimablekb))K")" # string |
|
|
|
|
|
|
|
swaptotal="$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapTotal /proc/meminfo | awk '{print $2}')K")" # string |
|
|
|
swapfree="$(numfmt --to=iec --from=iec --suffix=B "$(grep ^SwapFree /proc/meminfo | awk '{print $2}')K")" # string |
|
|
|
swapused="$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^SwapTotal /proc/meminfo | awk '{print $2}') - $(grep ^SwapFree /proc/meminfo | awk '{print $2}')))K")" # string |
|
|
|
# RAM usage of the game server pid |
|
|
|
# MB |
|
|
|
if [ "${gameserverpid}" ]; then |
|
|
|
memused="$(ps --forest -o rss -g "${gameserverpid}" | awk '{s+=$1} END {print s}' | awk '{$1/=1024;printf "%.0f",$1}{print $2}')" |
|
|
|
# % |
|
|
|
pmemused="$(ps --forest -o %mem -g "${gameserverpid}" | awk '{s+=$1} END {print s}')" |
|
|
|
memusedmb="$(ps --forest -o rss -g "${gameserverpid}" | awk '{s+=$1} END {print s}' | awk '{$1/=1024;printf "%.0f",$1}{print $2}')" # integer |
|
|
|
memusedpct="$(ps --forest -o %mem -g "${gameserverpid}" | awk '{s+=$1} END {print s}')" # integer |
|
|
|
fi |
|
|
|
else |
|
|
|
# Older distros will need to use free. |
|
|
@ -203,32 +205,32 @@ else |
|
|
|
else |
|
|
|
humanreadable="-h" |
|
|
|
fi |
|
|
|
physmemtotalmb="$(free -m | awk '/Mem:/ {print $2}')" |
|
|
|
physmemtotal="$(free ${humanreadable} | awk '/Mem:/ {print $2}')" |
|
|
|
physmemfree="$(free ${humanreadable} | awk '/Mem:/ {print $4}')" |
|
|
|
physmemused="$(free ${humanreadable} | awk '/Mem:/ {print $3}')" |
|
|
|
physmemtotalmb="$(free -m | awk '/Mem:/ {print $2}')" # string |
|
|
|
physmemtotal="$(free ${humanreadable} | awk '/Mem:/ {print $2}')" # string |
|
|
|
physmemfree="$(free ${humanreadable} | awk '/Mem:/ {print $4}')" # string |
|
|
|
physmemused="$(free ${humanreadable} | awk '/Mem:/ {print $3}')" # string |
|
|
|
|
|
|
|
oldfree="$(free ${humanreadable} | awk '/cache:/')" |
|
|
|
if [ "${oldfree}" ]; then |
|
|
|
physmemavailable="n/a" |
|
|
|
physmemcached="n/a" |
|
|
|
else |
|
|
|
physmemavailable="$(free ${humanreadable} | awk '/Mem:/ {print $7}')" |
|
|
|
physmemcached="$(free ${humanreadable} | awk '/Mem:/ {print $6}')" |
|
|
|
physmemavailable="$(free ${humanreadable} | awk '/Mem:/ {print $7}')" # string |
|
|
|
physmemcached="$(free ${humanreadable} | awk '/Mem:/ {print $6}')" # string |
|
|
|
fi |
|
|
|
|
|
|
|
swaptotal="$(free ${humanreadable} | awk '/Swap:/ {print $2}')" |
|
|
|
swapused="$(free ${humanreadable} | awk '/Swap:/ {print $3}')" |
|
|
|
swapfree="$(free ${humanreadable} | awk '/Swap:/ {print $4}')" |
|
|
|
swaptotal="$(free ${humanreadable} | awk '/Swap:/ {print $2}')" # string |
|
|
|
swapused="$(free ${humanreadable} | awk '/Swap:/ {print $3}')" # string |
|
|
|
swapfree="$(free ${humanreadable} | awk '/Swap:/ {print $4}')" # string |
|
|
|
fi |
|
|
|
|
|
|
|
### Disk information |
|
|
|
|
|
|
|
## Available disk space on the partition. |
|
|
|
filesystem="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $1}')" |
|
|
|
totalspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $2}')" |
|
|
|
usedspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $3}')" |
|
|
|
availspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $4}')" |
|
|
|
filesystem="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $1}')" # string e.g /dev/sda |
|
|
|
totalspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $2}')" # string e.g 20G |
|
|
|
usedspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $3}')" # string e.g 15G |
|
|
|
availspace="$(LC_ALL=C df -hP "${rootdir}" | tail -n 1 | awk '{print $4}')" # string e.g 5G |
|
|
|
|
|
|
|
## LinuxGSM used space total. |
|
|
|
rootdirdu="$(du -sh "${rootdir}" 2> /dev/null | awk '{print $1}')" |
|
|
|