Skip to content

Instantly share code, notes, and snippets.

@fwolf
Last active May 28, 2017 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fwolf/5856230 to your computer and use it in GitHub Desktop.
Save fwolf/5856230 to your computer and use it in GitHub Desktop.
Monitor memory usage in VPS
#! /bin/bash
# https://gist.github.com/fwolf/5856230
#ps aux --width 80 | sort -nrk +6 | head -n 15
# bsdtime is shorter than cputime, hh:mm:ss vs MMM:SS
ps -eo 'user,pid,%cpu,%mem,rss,vsz,stime,bsdtime,s,cmd' --sort '-rss,-vsz' --width 80 | head -n 16
echo
#ps auxm > /tmp/mem.sh
top -b -n1 > /tmp/mem.sh
M1=`cat /tmp/mem.sh | head -n4 | tail -n1`
echo $M1
M1=`cat /tmp/mem.sh | grep php-fpm | awk '{if (match($6, "m")) {gsub("m", "", $6); I += $6 * 1024} else {I += $6}} END {print I}'`
M2=`cat /tmp/mem.sh | grep php-fpm | wc -l`
echo FastCGI: $M2 process, "$M1"k memory.
M1=`cat /tmp/mem.sh | grep nginx | awk '{if (match($6, "m")) {gsub("m", "", $6); I += $6 * 1024} else {I += $6}} END {print I}'`
M2=`cat /tmp/mem.sh | grep nginx | wc -l`
echo Nginx: $M2 process, "$M1"k memory.
rm /tmp/mem.sh
echo
free -h | grep -v Mem | grep -v Swap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment