renamed: install_docker.sh -> install/docker.sh new file: install/packages.sh new file: monitoring/cpu.sh renamed: update.sh -> monitoring/update.sh
35 lines
1.0 KiB
Bash
35 lines
1.0 KiB
Bash
#!/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 |