Last active
May 28, 2017 09:13
-
-
Save fwolf/5856230 to your computer and use it in GitHub Desktop.
Monitor memory usage in VPS
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 | |
# 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