From 0248e202b0c5f0e42eca5a5d0215cff8a84d7e6b Mon Sep 17 00:00:00 2001 From: Guillaume Archambault Date: Sat, 21 Oct 2023 10:43:19 +0200 Subject: [PATCH] Changes to be committed: renamed: install_docker.sh -> install/docker.sh new file: install/packages.sh new file: monitoring/cpu.sh renamed: update.sh -> monitoring/update.sh --- install_docker.sh => install/docker.sh | 0 install/packages.sh | 31 +++++++++++++++++++++++ monitoring/cpu.sh | 35 ++++++++++++++++++++++++++ update.sh => monitoring/update.sh | 0 4 files changed, 66 insertions(+) rename install_docker.sh => install/docker.sh (100%) create mode 100644 install/packages.sh create mode 100644 monitoring/cpu.sh rename update.sh => monitoring/update.sh (100%) diff --git a/install_docker.sh b/install/docker.sh similarity index 100% rename from install_docker.sh rename to install/docker.sh diff --git a/install/packages.sh b/install/packages.sh new file mode 100644 index 0000000..978b7a9 --- /dev/null +++ b/install/packages.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Define color codes +GREEN='\033[0;32m' +RED='\033[0;31m' +RESET='\033[0m' # No Color + +# Packages list +packages=( + "exa" # Better than ls + "bat" # Better than cat + "btop" # Betther than top + "ncdu" # Better than du -h + "duf" # Better than df -h + "neofetch" # Because it's cool + "git" # Because git +) + +# Packages installation +clear +echo "Mise à jour de la liste des paquets..." +echo " " +sudo apt update >/dev/null 2>&1 +echo "Installation des paquets :" +for package in "${packages[@]}"; do + if sudo apt install "$package" -y >/dev/null 2>&1; then + echo -e " - Installation de $package : ${GREEN}ok${RESET}" + else + echo -e " - Installation de $package : ${RED}échoué${RESET}" + fi +done \ No newline at end of file diff --git a/monitoring/cpu.sh b/monitoring/cpu.sh new file mode 100644 index 0000000..eca2a77 --- /dev/null +++ b/monitoring/cpu.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# URL ntfy +NTFY_URL="my_url" +# Chemin vers le fichier journal +LOG_FILE="/var/log/cpu.log" +# Seuil de charge CPU en pourcentage +SEUIL_CPU=70 + +# Obtenir le nom du serveur à partir du hostname +SERVER_NAME=$(hostname) + +# Fonction pour obtenir la charge CPU actuelle +get_cpu_load() { + # Utilisation de la commande 'top' pour obtenir la charge CPU + cpu_load=$(top -bn1 | awk '/%Cpu/ {print $2}' | cut -d "." -f 1) + echo "$cpu_load" +} + +# Vérifier la charge CPU et envoyer une notification si nécessaire +check_cpu_load() { + cpu_usage=$(get_cpu_load) + + if [ "$cpu_usage" -gt "$SEUIL_CPU" ]; then + #top_processes=$(get_top_processes) + date >> $LOG_FILE + ps aux --sort=-%cpu | head -n 6 >> $LOG_FILE + message="La charge CPU du serveur ${SERVER_NAME} est de ${cpu_usage}% (seuil: ${SEUIL_CPU}%) voir logs dans /var/log/cpu.log" + title="!!!CPU(${SERVER_NAME})!!!" + curl -d "$message" ntfy.sh/$NTFY_URL?title=$title + fi +} + +# Appeler la fonction pour vérifier la charge CPU +check_cpu_load \ No newline at end of file diff --git a/update.sh b/monitoring/update.sh similarity index 100% rename from update.sh rename to monitoring/update.sh