Created
May 22, 2019 05:39
-
-
Save reazul-islam/348dee241371ea187c070a6e3112018d to your computer and use it in GitHub Desktop.
pm2 monitor and restart automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| memtotal=$(free | grep Mem | awk '{ print $2 }') | |
| memuse=$(free | grep Mem | awk '{ print $3 }') | |
| let "memusepercent = $memuse * 100 / $memtotal " | |
| let "memtolerance = ($memtotal * 90)/100 " | |
| echo "MemTotal: $memtotal (Usage tolerance: $memtolerance )" | |
| echo "MemUsed: $memuse ($memusepercent %)" | |
| if [ $memuse -ge $memtolerance ]; then | |
| echo "Memory use over 90%" | |
| pm2 restart all | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment