Created
January 16, 2020 19:03
-
-
Save qxcv/e61784a7ceb82eaa5b61e8711bc95f95 to your computer and use it in GitHub Desktop.
Bash script to track peak system memory usage (mem + swap)
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 | |
max_mem=0 | |
while [ true ]; do | |
# awk trick from https://stackoverflow.com/a/450821 | |
mem="$(free --giga | sed 's/ \+/ /g' | cut -d ' ' -f 3 | tail -n +2 | awk '{s+=$1} END {print s}')" | |
if [ "$mem" -gt "$max_mem" ]; then | |
max_mem="$mem" | |
echo "new peak ${max_mem}GB at $(date)" | |
fi | |
sleep 0.1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment