2021-11-04 13:16:25 +01:00
|
|
|
# **************************************************************************** #
|
|
|
|
|
# #
|
|
|
|
|
# ::: :::::::: #
|
|
|
|
|
# monitoring.sh :+: :+: :+: #
|
|
|
|
|
# +:+ +:+ +:+ #
|
|
|
|
|
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
|
|
|
|
# +#+#+#+#+#+ +#+ #
|
|
|
|
|
# Created: 2021/11/04 12:36:53 by gbaconni #+# #+# #
|
2021-11-04 13:32:00 +01:00
|
|
|
# Updated: 2021/11/04 13:31:59 by gbaconni ### lausanne.ch #
|
2021-11-04 13:16:25 +01:00
|
|
|
# #
|
|
|
|
|
# **************************************************************************** #
|
|
|
|
|
|
|
|
|
|
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 ()
|
|
|
|
|
{
|
2021-11-04 13:29:13 +01:00
|
|
|
free -m | awk '/Mem:/ { total=$2; used=total-$3; } END { printf "#Memory Usage: %d/%dMB (%.2f%%)\n", used, total, (used * 100) / total; }'
|
2021-11-04 13:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ft_disk ()
|
|
|
|
|
{
|
|
|
|
|
df --total -l -t ext2 -t ext3 -t ext4 -t xfs \
|
2021-11-04 13:29:13 +01:00
|
|
|
| awk '/^total/ { total=$2; used=$3; pcent=$4 } END { printf "#Disk Usage: %d/%dGb (%.2f%%)\n", used * 8, (total * 8) / (1000 * 1000 * 1000), pcent; }'
|
2021-11-04 13:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main ()
|
|
|
|
|
{
|
2021-11-04 13:32:00 +01:00
|
|
|
source /etc/defaut/monitoring
|
2021-11-04 13:29:57 +01:00
|
|
|
if [ "${MONITORING}" != "yes" ]
|
2021-11-04 13:16:25 +01:00
|
|
|
then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
ft_arch
|
|
|
|
|
ft_cpu
|
|
|
|
|
ft_memory
|
|
|
|
|
ft_disk
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main $@
|
|
|
|
|
exit $?
|