Modification des infons de connexions
This commit is contained in:
parent
f7b589a070
commit
b7e2c7a068
@ -1,4 +1,3 @@
|
||||
|
||||
# Hard Drive usage
|
||||
function hddtop() {
|
||||
df -TPh \
|
||||
@ -16,16 +15,6 @@ function hddtop() {
|
||||
| column -t
|
||||
}
|
||||
|
||||
# List all ip's v4
|
||||
#
|
||||
# OLD
|
||||
#ip4all () {
|
||||
# ip -4 -o addr \
|
||||
# | grep -v 127.0.0 \
|
||||
# | awk -v blue="$(tput bold;tput setaf 4)" -v reset="$(tput sgr0)" '{printf "%s\t%s\t%s %s %s\n",$2,":",blue,$4,reset}'
|
||||
#}
|
||||
#
|
||||
# NEW
|
||||
function ip4all()
|
||||
{
|
||||
echo -e "\033[32mInterfaces and IP\033[00m :"
|
||||
@ -39,6 +28,126 @@ function ip4all()
|
||||
done
|
||||
}
|
||||
|
||||
function template_check_cpu(){
|
||||
|
||||
# Nombre de cpu
|
||||
nb_cpu=$(cat /proc/cpuinfo | grep -c processor)
|
||||
# Initialisation d'un warning
|
||||
warning_cpu=$(bc -l <<< "$nb_cpu * 0.75")
|
||||
# Initialisation d'un critical
|
||||
critical_cpu=$(bc -l <<< "$nb_cpu * 0.9")
|
||||
|
||||
# Affichage du pourcentage CPU utilisée, avec coloration
|
||||
echo $(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>'$critical_cpu'?red:(+$1>'$warning_cpu')?yellow:green), $1, reset}' \
|
||||
/proc/loadavg) \
|
||||
/ $nb_cpu CPU
|
||||
}
|
||||
|
||||
function template_uptime(){
|
||||
|
||||
# Affichage familier du uptime
|
||||
if lsb_release -d |grep -Ei 'Debian|Red Hat|Ubuntu' > /dev/null;then
|
||||
echo "$(uptime --pretty)"
|
||||
# Suse n'embarque pas encore cette option
|
||||
elif lsb_release -d |grep -i 'SUSE' > /dev/null;then
|
||||
echo "Depuis le $(who -b |awk '{print $3, "-" ,$4}')"
|
||||
else
|
||||
# Tant pis, vous aurez un affichage moche
|
||||
echo "$(uptime)"
|
||||
fi
|
||||
}
|
||||
|
||||
function template_check_swappiness(){
|
||||
|
||||
# cette fonction nous sera utile pour les deux suivantes : check_memory et check_swap
|
||||
|
||||
# vm.swappiness = 0 – Linux utilisera le HD en dernière limite pour éviter un manque de RAM.
|
||||
# vm.swappiness = 60 – Valeur par défaut de Linux : à partir de 40% d’occupation de Ram, le noyau écrit sur le disque.
|
||||
# vm.swappiness = 100 – tous les accès se font en écriture dans la SWAP.
|
||||
|
||||
swapiness=$(cat /proc/sys/vm/swappiness)
|
||||
(( swapiness = 100 - swapiness))
|
||||
(( mi_swapiness = swapiness / 2 ))
|
||||
}
|
||||
function template_check_memory(){
|
||||
|
||||
|
||||
# Récupération des valeurs de swapiness
|
||||
template_check_swappiness
|
||||
|
||||
# Mémoire disponible = Cached + Buffers + MemFree
|
||||
memory_avail=$(grep 'MemAvailable' /proc/meminfo | awk '{print $2}')
|
||||
# Mémoire total
|
||||
memory_total=$(grep 'MemTotal' /proc/meminfo | awk '{print $2}')
|
||||
|
||||
# Calcul en pourcentage de la mémoire utilisée
|
||||
pourcent_memory_used=$(bc -l <<< " 100 - ($memory_avail / $memory_total * 100)")
|
||||
|
||||
# Selon la variable LANG, le printf acceptera les '.' ou les ',' pour un affichage clair et précis
|
||||
if [[ "$LANG" == 'fr_FR.UTF-8' ]];then
|
||||
pourcent_memory_used=$(printf %1.1f%% $(echo $pourcent_memory_used|sed 's/\./\,/'))
|
||||
else
|
||||
pourcent_memory_used=$(printf %1.1f%% $(echo $pourcent_memory_used))
|
||||
fi
|
||||
|
||||
# Affichage du pourcentage de la mémoire utilisée, avec coloration
|
||||
echo "$pourcent_memory_used" \
|
||||
|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}'
|
||||
|
||||
}
|
||||
|
||||
function template_check_swap(){
|
||||
|
||||
# Calcul de l'utilisation de la SWAP si présente
|
||||
if [[ $(grep SwapTotal /proc/meminfo | awk '{print $2}') -ne 0 ]];then
|
||||
template_check_swappiness
|
||||
# Swap libre
|
||||
SwapFree=$(grep SwapFree /proc/meminfo | awk '{print $2}')
|
||||
# Swap totale
|
||||
SwapTotal=$(grep SwapTotal /proc/meminfo | awk '{print $2}')
|
||||
# Calcul du pourcentage de la swap utilisée
|
||||
pourcent_swap_used=$(bc -l <<< "($SwapTotal - $SwapFree) / $SwapTotal * 100")
|
||||
# Selon la variable LANG, le printf acceptera les '.' ou les ',' pour un affichage clair et précis
|
||||
if [[ "$LANG" == 'fr_FR.UTF-8' ]];then
|
||||
pourcent_swap_used=$(printf %1.1f%% $(echo $pourcent_swap_used|sed 's/\./\,/'))
|
||||
else
|
||||
pourcent_swap_used=$(printf %1.1f%% $(echo $pourcent_swap_used))
|
||||
fi
|
||||
|
||||
# Affichage du pourcentage de la swap utilisée, avec coloration
|
||||
echo $pourcent_swap_used \
|
||||
|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}'
|
||||
else
|
||||
# Si aucune swap présente
|
||||
echo 'NO SWAP'
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function check_cron() {
|
||||
nb_cron=$(wc -l <<< $(grep -Ev 'SHEL|PATH|MAILTO|anacron|run-parts|#|^$' /etc/crontab))
|
||||
echo $nb_cron
|
||||
}
|
||||
|
||||
# Show top usage memory
|
||||
function memtop () {
|
||||
ps -eo size,pid,user,command --sort -size \
|
||||
|
@ -1,55 +1,25 @@
|
||||
|
||||
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
|
||||
echo -e "
|
||||
|
||||
$(ip4all)
|
||||
|
||||
$(hddtop)
|
||||
|
||||
$(tput bold)$(tput setaf 4)Système$(tput sgr0)
|
||||
|
||||
- OS : $(lsb_release -d | sed -e 's/Description://g' | sed 's/^[ \t]*//')
|
||||
- Kernel : $(uname -srmo)
|
||||
- Uptime : $(template_uptime)
|
||||
- Charge Cpu : $(template_check_cpu)
|
||||
- Utilisation mémoire : $(template_check_memory)
|
||||
- Utilisation Swap : $(template_check_swap)
|
||||
- Nombre de processus : $(ps aux | wc -l)
|
||||
- Utilisateur(s) : $(users | wc -w)
|
||||
- Crons : $(check_cron)
|
||||
"
|
||||
|
||||
# If reboot is required
|
||||
if [ -f /run/reboot-required ] ; then
|
||||
echo -e "$(tput setaf 1)\tReboot is required$(tput sgr0)"
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user