conf-99-basic_config_debian/root/.profile.d/01_stats_connexion.conf

56 lines
1.6 KiB
Plaintext
Raw Normal View History

date=`date +"%Y-%m-%d - %T"`
# LOAD AVERAGE
load=$(cat /proc/loadavg |awk -v red="$(tput setaf 1)" -v yellow="$(tput setaf 3)" -v green="$(tput setaf 2)" -v reset="$(tput sgr0)" '{printf "%s%s%s\n", (+$1>1?red:(+$1>0.7)?yellow:green), $1, reset}')
# CALCULATE SWAPINESS FOR MEMOIRE ET SWAP
swapiness=`sysctl vm.swappiness |awk '{print $3}'`
(( swapiness = 100 - swapiness))
(( mi_swapiness = swapiness / 2 ))
# MEMORY
memory_usage=$(free -m| grep 'Mem' |awk ' {total=$2} {avalaible=$7} END { printf("%3.1f%%", 100-avalaible/total*100)}' |awk -v red="$(tput setaf 1)" -v yellow="$(tput setaf 3)" -v green="$(tput setaf 2)" -v reset="$(tput sgr0)" '{printf "%s%s%s\n", (+$1>'$swapiness'?red:(+$1>'$mi_swapiness')?yellow:green), $1, reset}')
# SWAP
if [ $(grep SwapTotal /proc/meminfo |awk '{print $2}') -gt 0 ] ; then
# if swap exist
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
var4=${swap_usage%.*}
((var4 >= 1 )) && swap_usage="\033[31m$swap_usage\033[00m" || swap_usage="\033[32m$swap_usage\033[00m"
else
# if swap is absent
swap_usage="NO SWAP"
fi
# USERS AND OTHERS
users=`users | wc -w`
processes=`ps aux | wc -l`
############# SHOW #############
echo
echo -e "OS\t:\t `lsb_release -d | sed -e 's/Description://g' | sed 's/^[ \t]*//'`"
echo -e "Uptime\t:\t $(uptime -p)"
echo
ip4all
echo
hddtop
echo
echo -e "CPU Load\t:\t$load"
echo -e "Memory usage\t:\t$memory_usage"
echo -e "Swap usage\t:\t$swap_usage"
echo -e "Process number\t:\t$processes"
echo
# If reboot is required
if [ -f /run/reboot-required ] ; then
echo -e "$(tput setaf 1)\tReboot is required$(tput sgr0)"
fi