Created
July 13, 2018 19:26
-
-
Save jsanta/de1614ce7d2cc79de891292b3253b2b5 to your computer and use it in GitHub Desktop.
Script to restart PM2 procceses if memory exceeds limit
This file contains 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 * 0.9 " | |
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