Last active
August 29, 2015 14:18
-
-
Save phptek/d26d69125bc890e9a3de to your computer and use it in GitHub Desktop.
Monitor RAM usage during a siege
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 | |
# | |
# Russell Michell 2015 <russell.michell@deviate.net.nz> | |
# | |
# Custom wrapper around /proc/meminfo designed to be invoked by something like `watch -n1 maxmem.sh` | |
# and run on a server under siege for RAM usage analysis. The script outputs used memory in Mb to a file which can | |
# be further analysed thus: | |
# | |
# cat outfile.out | sort -nr | head -1 | |
# | |
# TODO: | |
# Modify the trap logic to detect an "upstream" quit from watch | |
OUTFILE="maxmem.out" | |
if [ ! -f $OUTFILE ]; then | |
touch $OUTFILE | |
chmod u+rw $OUTFILE | |
fi | |
MEM_TOTAL=$( sudo cat /proc/meminfo | awk '/MemTotal:/' | awk '{ print $2 }' ) | |
MEM_FREE=$( sudo cat /proc/meminfo | awk '/MemFree:/' | awk '{ print $2 }' ) | |
MEM_USED=$( echo "$MEM_TOTAL-$MEM_FREE" | bc ) | |
MEM_CONV=$( echo "$MEM_USED/1024" | bc ) | |
echo $MEM_CONV >> $OUTFILE | |
# Display peak usage when user quits the "parent" watch command | |
#trap "cat $OUTFILE | sort -nr ); exit(1)" INT TERM | |
#echo ${PIPESTATUS[0]} >> $OUTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment