From 8830bad9a891d3a46a7c010f323c3f76b450e24c Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 30 Oct 2023 21:05:32 +0000 Subject: [PATCH] Feature/stats change (#4363) * feat: update unsupprted distros and add comments to info_distro * remove tmux 1.6 code * add java and tmux version and change ram to int * tidy up ram requirements used data gathered from analytics --- lgsm/modules/check_deps.sh | 4 +- lgsm/modules/check_system_requirements.sh | 57 ++++--- lgsm/modules/command_debug.sh | 2 +- lgsm/modules/command_start.sh | 46 ++---- lgsm/modules/info_distro.sh | 184 +++++++++++----------- lgsm/modules/info_messages.sh | 8 +- lgsm/modules/info_stats.sh | 18 ++- 7 files changed, 154 insertions(+), 165 deletions(-) diff --git a/lgsm/modules/check_deps.sh b/lgsm/modules/check_deps.sh index 0f8304a18..b7b9f4758 100644 --- a/lgsm/modules/check_deps.sh +++ b/lgsm/modules/check_deps.sh @@ -349,8 +349,8 @@ fi # Will warn user if their distro is no longer supported by the vendor. if [ -n "${distrosupport}" ]; then if [ "${distrosupport}" == "unsupported" ]; then - fn_print_warning_nl "${distroname} is no longer supported by the vendor. Upgrading is recommended." - fn_script_log_warn "${distroname} is no longer supported by the vendor. Upgrading is recommended." + fn_print_warning_nl "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended." + fn_script_log_warn "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended." fi fi diff --git a/lgsm/modules/check_system_requirements.sh b/lgsm/modules/check_system_requirements.sh index 6932de4dc..bdf1a51c1 100644 --- a/lgsm/modules/check_system_requirements.sh +++ b/lgsm/modules/check_system_requirements.sh @@ -12,42 +12,57 @@ info_distro.sh # RAM requirements in megabytes for each game or engine. if [ "${shortname}" == "ark" ]; then - ramrequirementmb="4000" - ramrequirementgb="4" + ramrequirementgb="7" +elif [ "${shortname}" == "arma3" ]; then + ramrequirementgb="2" +elif [ "${shortname}" == "armar" ]; then + ramrequirementgb="3" elif [ "${shortname}" == "bt" ]; then - ramrequirementmb="1000" ramrequirementgb="1" -elif [ "${shortname}" == "mh" ]; then - ramrequirementmb="4000" - ramrequirementgb="4" -elif [ "${shortname}" == "arma3" ]; then - ramrequirementmb="1000" +elif [ "${shortname}" == "cc" ]; then ramrequirementgb="1" -elif [ "${shortname}" == "rust" ]; then - ramrequirementmb="4000" +elif [ "${shortname}" == "dayz" ]; then + ramrequirementgb="5" +elif [ "${shortname}" == "dodr" ]; then + ramrequirementgb="2" +elif [ "${shortname}" == "hw" ]; then + ramrequirementgb="3" +elif [ "${shortname}" == "mc" ]; then + ramrequirementgb="1" +elif [ "${shortname}" == "pmc" ]; then + ramrequirementgb="2" +elif [ "${shortname}" == "mh" ]; then ramrequirementgb="4" -elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "wmc" ]; then - ramrequirementmb="1000" +elif [ "${shortname}" == "ns2" ] || [ "${shortname}" == "ns2c" ]; then ramrequirementgb="1" elif [ "${shortname}" == "ps" ]; then - ramrequirementmb="2000" ramrequirementgb="2" -elif [ "${shortname}" == "ns2" ] || [ "${shortname}" == "ns2c" ]; then - ramrequirementmb="1000" +elif [ "${shortname}" == "pvr" ]; then ramrequirementgb="1" +elif [ "${shortname}" == "pz" ]; then + ramrequirementgb="3" +elif [ "${shortname}" == "rust" ]; then + ramrequirementgb="9" +elif [ "${shortname}" == "sdtd" ]; then + ramrequirementgb="4" +elif [ "${shortname}" == "squad" ]; then + ramrequirementgb="2" elif [ "${shortname}" == "st" ]; then - ramrequirementmb="1000" ramrequirementgb="1" -elif [ "${shortname}" == "pvr" ]; then - ramrequirementmb="2000" +elif [ "${shortname}" == "stn" ]; then + ramrequirementgb="3" +elif [ "${shortname}" == "tu" ]; then + ramrequirementgb="2" +elif [ "${shortname}" == "vh" ]; then ramrequirementgb="2" +else + ramrequirementgb="0.5" fi # If the game or engine has a minimum RAM Requirement, compare it to system's available RAM. -if [ "${ramrequirementmb}" ]; then - if [ "${physmemtotalmb}" -lt "${ramrequirementmb}" ]; then +if [ "${ramrequirementgb}" ]; then + if [ "${physmemtotalgb}" -lt "${ramrequirementgb}" ]; then fn_print_dots "Checking RAM" - # Warn the user. fn_print_warn_nl "Checking RAM: ${ramrequirementgb}G required, ${physmemtotal} available" echo "* ${gamename} server may fail to run or experience poor performance." fn_sleep_time_5 diff --git a/lgsm/modules/command_debug.sh b/lgsm/modules/command_debug.sh index 495417c16..2e6c0e2e2 100644 --- a/lgsm/modules/command_debug.sh +++ b/lgsm/modules/command_debug.sh @@ -34,7 +34,7 @@ fn_print_header echo -e "${lightblue}Architecture:\t\t${default}${arch}" echo -e "${lightblue}Kernel:\t\t${default}${kernel}" echo -e "${lightblue}Hostname:\t\t${default}${HOSTNAME}" - echo -e "${lightblue}tmux:\t\t${default}${tmuxv}" + echo -e "${lightblue}tmux:\t\t${default}${tmuxversion}" echo -e "${lightblue}Avg Load:\t\t${default}${load}" echo -e "${lightblue}Free Memory:\t\t${default}${physmemfree}" echo -e "${lightblue}Free Disk:\t\t${default}${availspace}" diff --git a/lgsm/modules/command_start.sh b/lgsm/modules/command_start.sh index 345ede786..f38125a5e 100644 --- a/lgsm/modules/command_start.sh +++ b/lgsm/modules/command_start.sh @@ -73,47 +73,23 @@ fn_start_tmux() { touch "${consolelog}" # tmux compiled from source will return "master", therefore ignore it. - if [ "${tmuxv}" == "master" ]; then + if [ "${tmuxversion}" == "master" ]; then fn_script_log "tmux version: master (user compiled)" echo -e "tmux version: master (user compiled)" >> "${consolelog}" - if [ "${consolelogging}" == "on" ] || [ -z "${consolelogging}" ]; then - if [ "${logtimestamp}" == "on" ]; then - tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $addtimestamp\" >> '${consolelog}'" - else - tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" - fi - fi + fi - elif [ -n "${tmuxv}" ]; then - # tmux pipe-pane not supported in tmux versions < 1.6. - if [ "${tmuxvdigit}" -lt "16" ]; then - echo -e "Console logging disabled: tmux => 1.6 required - https://linuxgsm.com/tmux-upgrade - Currently installed: $(tmux -V)" > "${consolelog}" - - # Console logging disabled: Bug in tmux 1.8 breaks logging. - elif [ "${tmuxvdigit}" -eq "18" ]; then - echo -e "Console logging disabled: Bug in tmux 1.8 breaks logging - https://linuxgsm.com/tmux-upgrade - Currently installed: $(tmux -V)" > "${consolelog}" - # Console logging enable or not set. - elif [ "${consolelogging}" == "on" ] || [ -z "${consolelogging}" ]; then - if [ "${logtimestamp}" == "on" ]; then - tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $addtimestamp\" >> '${consolelog}'" - else - tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" - fi + # Enable console logging. + if [ "${consolelogging}" == "on" ] || [ -z "${consolelogging}" ]; then + if [ "${logtimestamp}" == "on" ]; then + tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $addtimestamp\" >> '${consolelog}'" + else + tmux -L "${socketname}" pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" fi else - echo -e "Unable to detect tmux version" >> "${consolelog}" - fn_script_log_warn "Unable to detect tmux version" - fi - - # Console logging disabled. - if [ "${consolelogging}" == "off" ]; then echo -e "Console logging disabled in settings" >> "${consolelog}" - fn_script_log_info "Console logging disabled by user" + fn_script_log_info "Console logging disabled in settings" fi + fn_sleep_time_1 # If the server fails to start. @@ -123,7 +99,7 @@ fn_start_tmux() { fn_script_log_fail "Unable to start ${servername}" if [ -s "${lgsmlogdir}/.${selfname}-tmux-error.tmp" ]; then fn_print_fail_nl "Unable to start ${servername}: tmux error:" - fn_script_log_fail "Unable to start ${servername}: tmux error:" + fn_script_log_fail "Unable to start ${servername}: tmux error" echo -e "" echo -e "Command" fn_messages_separator diff --git a/lgsm/modules/info_distro.sh b/lgsm/modules/info_distro.sh index a5607ef45..828946139 100644 --- a/lgsm/modules/info_distro.sh +++ b/lgsm/modules/info_distro.sh @@ -21,114 +21,107 @@ 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 -else - distrosupport=unknown +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="supported" + fi fi ## Glibc version -# e.g: 1.17 -glibcversion="$(ldd --version | sed -n '1s/.* //p')" +glibcversion="$(ldd --version | sed -n '1s/.* //p')" # e.g: 2.17 ## tmux version -# e.g: tmux 1.6 -if [ ! "$(command -V tmux 2> /dev/null)" ]; then - tmuxv="${red}NOT INSTALLED!${default}" - tmuxvdigit="0" -else - tmuxvdigit="$(tmux -V | sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')" - if [ "${tmuxvdigit}" -lt "16" ]; then - tmuxv="$(tmux -V) (>= 1.6 required for console log)" - else - tmuxv="$(tmux -V)" - fi +if [ "$(command -V tmux 2> /dev/null)" ]; then + tmuxversion="$(tmux -V | awk '{print $2}')" # e.g: tmux 3.3 fi if [ "$(command -V java 2> /dev/null)" ]; then - javaversion="$(java -version 2>&1 | grep "version")" + javaversion="$(java -version 2>&1 | grep "version")" # e.g: openjdk version "17.0.8.1" 2023-08-24 fi if [ "$(command -v mono 2> /dev/null)" ]; then - monoversion="$(mono --version 2>&1 | grep -Po '(?<=version )\d')" + monoversion="$(mono --version 2>&1 | grep -Po '(?<=version )\d')" # e.g: 6 fi if [ "$(command -v dotnet 2> /dev/null)" ]; then - dotnetversion="$(dotnet --list-runtimes | grep -E 'Microsoft\.NETCore\.App' | awk '{print $2}')" + dotnetversion="$(dotnet --list-runtimes | grep -E 'Microsoft\.NETCore\.App' | awk '{print $2}')" # e.g: 6.0.0 fi ## Uptime @@ -141,16 +134,16 @@ days="$((uptime / 60 / 60 / 24))" ### Performance information ## Average server load -load="$(uptime | awk -F 'load average: ' '{ print $2 }')" +load="$(uptime | awk -F 'load average: ' '{ print $2 }')" # e.g 0.01, 0.05, 0.11 ## CPU information -cpumodel="$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')" +cpumodel="$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')" # e.g Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz cpucores="$(awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo)" -cpufreqency="$(awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')" +cpufreqency="$(awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')" # e.g 2394.503 # CPU usage of the game server pid if [ -n "${gameserverpid}" ]; then - cpuused="$(ps --forest -o pcpu -g "${gameserverpid}" | awk '{s+=$1} END {print s}')" - cpuusedmhz="$(echo "${cpufreqency} * ${cpuused} / 100" | bc)" + cpuused="$(ps --forest -o pcpu -g "${gameserverpid}" | awk '{s+=$1} END {print s}')" # integer + cpuusedmhz="$(echo "${cpufreqency} * ${cpuused} / 100" | bc)" # integer fi ## Memory information @@ -161,36 +154,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 # integer + physmemtotalgb="$(((physmemtotalmb + 512) / 1024))" # integer # 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 +195,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}')" @@ -263,21 +255,21 @@ if [ -d "${backupdir}" ]; then # If there are backups in backup dir. if [ "$(find "${backupdir}" -name "*.tar.gz" | wc -l)" -ne "0" ]; then # number of backups. - backupcount="$(find "${backupdir}"/*.tar.gz | wc -l)" + backupcount="$(find "${backupdir}"/*.tar.gz | wc -l)" # integer # most recent backup. - lastbackup="$(ls -1t "${backupdir}"/*.tar.gz | head -1)" + lastbackup="$(ls -1t "${backupdir}"/*.tar.gz | head -1)" # string # date of most recent backup. - lastbackupdate="$(date -r "${lastbackup}")" + lastbackupdate="$(date -r "${lastbackup}")" # string # no of days since last backup. - lastbackupdaysago="$((($(date +'%s') - $(date -r "${lastbackup}" +'%s')) / 60 / 60 / 24))" + lastbackupdaysago="$((($(date +'%s') - $(date -r "${lastbackup}" +'%s')) / 60 / 60 / 24))" # integer # size of most recent backup. - lastbackupsize="$(du -h "${lastbackup}" | awk '{print $1}')" + lastbackupsize="$(du -h "${lastbackup}" | awk '{print $1}')" # string fi fi # Network Interface name -netint=$(${ipcommand} -o addr | grep "${ip}" | awk '{print $2}') -netlink=$(${ethtoolcommand} "${netint}" 2> /dev/null | grep Speed | awk '{print $2}') +netint=$(${ipcommand} -o addr | grep "${ip}" | awk '{print $2}') # e.g eth0 +netlink=$(${ethtoolcommand} "${netint}" 2> /dev/null | grep Speed | awk '{print $2}') # e.g 1000Mb/s # Sets the SteamCMD glibc requirement if the game server requirement is less or not required. if [ "${appid}" ]; then @@ -286,5 +278,5 @@ if [ "${appid}" ]; then fi fi -# Gather Port Info using ss +# Gather Port Info using ss. ssinfo="$(ss -tuplwn)" diff --git a/lgsm/modules/info_messages.sh b/lgsm/modules/info_messages.sh index 0b928aa55..926165b28 100644 --- a/lgsm/modules/info_messages.sh +++ b/lgsm/modules/info_messages.sh @@ -95,7 +95,7 @@ fn_info_messages_distro() { echo -e "${lightblue}Hostname:\t${default}${HOSTNAME}" echo -e "${lightblue}Environment:\t${default}${virtualenvironment}" echo -e "${lightblue}Uptime:\t${default}${days}d, ${hours}h, ${minutes}m" - echo -e "${lightblue}tmux:\t${default}${tmuxv}" + echo -e "${lightblue}tmux:\t${default}${tmuxversion}" echo -e "${lightblue}glibc:\t${default}${glibcversion}" if [ -n "${javaram}" ]; then echo -e "${lightblue}Java:\t${default}${javaversion}" @@ -191,10 +191,10 @@ fn_info_messages_gameserver_resource() { else echo -e "${lightblue}CPU Used:\t${red}unknown${default}" fi - if [ -n "${memused}" ]; then - echo -e "${lightblue}Mem Used:\t${default}${pmemused}%\t${memused}MB${default}" + if [ -n "${memusedmb}" ]; then + echo -e "${lightblue}Mem Used:\t${default}${memusedpct}%\t${memusedmb}MB${default}" else - echo -e "${lightblue}Mem Used:\t${default}${pmemused}\t${red}unknown${default}" + echo -e "${lightblue}Mem Used:\t${default}${memusedpct}\t${red}unknown${default}" fi else echo -e "${lightblue}CPU Used:\t${default}0%${default}" diff --git a/lgsm/modules/info_stats.sh b/lgsm/modules/info_stats.sh index 8f0119532..dcc247b59 100644 --- a/lgsm/modules/info_stats.sh +++ b/lgsm/modules/info_stats.sh @@ -54,7 +54,10 @@ uuidhardware=$(cat "/etc/machine-id") # nearest 100Mhz. cpuusedmhzroundup="$(((cpuusedmhz + 99) / 100 * 100))" # nearest 100MB -memusedroundup="$(((memused + 99) / 100 * 100))" +memusedmbroundup="$(((memusedmb + 99) / 100 * 100))" + +# Convert any commas to dots. +physmemtotal="${physmemtotal//,/.}" apisecret="A-OzP02TSMWt4_vHi6ZpUw" measurementid="G-0CR8V7EMT5" @@ -66,22 +69,25 @@ payload="{ { \"name\": \"LinuxGSM\", \"params\": { - \"cpuusedmhzroundup\": \"${cpuusedmhzroundup}MHz\", + \"cpuusedmhzroundup\": \"${cpuusedmhzroundup}\", \"diskused\": \"${serverfilesdu}\", \"distro\": \"${distroname}\", \"game\": \"${gamename}\", - \"memusedroundup\": \"${memusedroundup}MB\", - \"ramused\": \"${memusedroundup}MB\", + \"memusedmbroundup\": \"${memusedmbroundup}\", + \"ramused\": \"${memusedmbroundup}\", \"servercpu\": \"${cpumodel} ${cpucores} cores\", \"servercpufreq\": \"${cpufreqency} x${cpucores}\", \"serverdisk\": \"${totalspace}\", \"serverfilesdu\": \"${serverfilesdu}\", \"serverram\": \"${physmemtotal}\", + \"serverramgb\": \"${physmemtotalgb}\", \"uuidhardware\": \"${uuidhardware}\", \"uuidinstall\": \"${uuidinstall}\", \"uuidinstance\": \"${uuidinstance}\", \"version\": \"${version}\", - \"virtualenvironment\": \"${virtualenvironment}\" + \"virtualenvironment\": \"${virtualenvironment}\", + \"tmuxversion\": \"${tmuxversion}\", + \"java\": \"${javaversion}\" } } ] @@ -156,7 +162,7 @@ fn_script_log_info "* uuid-hardware: ${uuidhardware}" fn_script_log_info "* Game Name: ${gamename}" fn_script_log_info "* Distro Name: ${distroname}" fn_script_log_info "* Game Server CPU Used: ${cpuusedmhzroundup}MHz" -fn_script_log_info "* Game Server RAM Used: ${memusedroundup}MB" +fn_script_log_info "* Game Server RAM Used: ${memusedmbroundup}MB" fn_script_log_info "* Game Server Disk Used: ${serverfilesdu}" fn_script_log_info "* Server CPU Model: ${cpumodel}" fn_script_log_info "* Server CPU Frequency: ${cpufreqency}"