Skip to content

Instantly share code, notes, and snippets.

@jhowbhz
Last active January 6, 2024 04:04
Show Gist options
  • Save jhowbhz/698c1729b2e25443de97691be389fbc4 to your computer and use it in GitHub Desktop.
Save jhowbhz/698c1729b2e25443de97691be389fbc4 to your computer and use it in GitHub Desktop.
Monitoring script sh
#! /bin/bash
# Add crontab -e line */1 * * * * /opt/resource.sh
MEMORY=$(free -m | awk 'NR==2{printf "%6.2f%%", $3*100/$2 }')
DISK=$(df -h | awk '$NF=="/"{printf "%6s", $5}')
CPU=$(top -bn1 | grep load | awk '{printf "%6.2f%%", $(NF-2)}')
MESSAGE="*Servidor*\n-----\n*Servidor:* APIS\n*Memória*: $MEMORY\n*Disco*:$DISK\n*CPU:*$CPU"
curl --location -g --request POST 'https://youserver.api/sendText' \
--header 'Content-Type: application/json' \
--header 'sessionkey: yourSessionKey' \
--data-raw '{
"session" : "yourSession",
"number" : "5531994359434",
"text" : "'"$MESSAGE"'"
}'
#! /bin/bash
# Others option
MEMORY=$(free -m | awk 'NR==2{print $3*100/$2 }')
CPU=$(top -bn1 | grep load | awk '{print $(NF-2)*100 }')
if (( $(echo "$MEMORY > 70" | bc -l) )) || (( $(echo "$CPU > 70" | bc -l) )); then
DISK=$(df -h | awk '$NF=="/"{printf "%6s", $5}')
MESSAGE="*Servidor*\n-----\n*Servidor:* APIS\n*Memória*: $MEMORY%\n*Disco*:$DISK\n*CPU:*$CPU%"
curl --location -g --request POST 'https://youserver.api/sendText' \
--header 'Content-Type: application/json' \
--header 'sessionkey: yourSessionKey' \
--data-raw '{
"session" : "yourSession",
"number" : "5531994359434",
"text" : "'"$MESSAGE"'"
}'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment