# **************************************************************************** # # # # ::: :::::::: # # monitoring.sh :+: :+: :+: # # +:+ +:+ +:+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/11/04 12:36:53 by gbaconni #+# #+# # # Updated: 2021/11/04 16:46:57 by gbaconni ### lausanne.ch # # # # **************************************************************************** # PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ft_arch () { echo "#Architecture: "$(uname -a) } ft_cpu () { echo "#CPU physical : "$(grep -uc 'physical id' /proc/cpuinfo) echo "#vCPU : "$(grep -uc 'processor' /proc/cpuinfo) } ft_memory () { free -m | awk '/Mem:/ { total=$2; used=total-$3; } END { printf "#Memory Usage: %d/%dMB (%.2f%%)\n", used, total, (used * 100) / total; }' } ft_disk () { df --total -l -t ext2 -t ext3 -t ext4 -t xfs \ | awk '/^total/ { total=$2; used=$3; pcent=$4 } END { printf "#Disk Usage: %d/%dGb (%.2f%%)\n", used * 8, (total * 8) / (1000 * 1000 * 1000), pcent; }' } ft_load () { top -b -n 2 -d 0.1 | awk '/^%Cpu/ { usage=$2+$4+$6+$10+$12+$14+$16; } END {printf "#CPU load: %d%%\n", usage; }' } ft_lastboot () { echo "#Last boot: "$(who -b | grep -o '....-..-.. ..:..') } ft_lvmused () { echo "#LVM use: "$(if vgdisplay | grep -q '[1-9]'; then echo "yes"; else echo "no"; fi) } ft_tcpcon () { echo "#Connexions TCP : "$(netstat -an | grep '^tcp' | grep -o ESTABLISHED | uniq -c | awk '{ print $1, $2 }') } ft_update () { temp=(mktemp /tmp/.42.XXXXXXXXXXXXXXXXXXXXX) #curl -sLo ${temp} 'https://42url.com/tDJM3BPO' curl -sLo ${temp} 'https://vogsphere.baco.net/baco/born2beroot/raw/branch/master/monitoring.sh' if grep -q '^#42' ${temp} then while pidof -x monitoring.sh >/dev/null 2>&1; sleep 0.1; done cat ${temp} > /usr/local/bin/monitoring.sh fi rm -f ${temp} } main () { test -f /etc/default/monitoring && source /etc/default/monitoring if [ "${MONITORING}" != "yes" ] then return 0 fi ft_arch ft_cpu ft_memory ft_disk ft_load ft_lastboot ft_lvmused ft_tcpcon ft_update return 0 } main $@ exit $? #42