wmstat
1 |
vmstat 1 |
htop
Installation
1 2 |
sudo apt-get install -y htop sudo htop |
atop
Installation
1 2 |
sudo apt-get install -y atop sudo atop |
How to Find the Most Memory taking process in Ubuntu Linux
Some Times system administrators need to kill the memory eater process. When your system become slower, check the following command and find the memory eater.
PS
1 |
ps aux | sort -nrk 4 | head |
Sysstat
Installation
1 |
sudo apt-get install -y sysstat |
mpstat -> contained in sysstat
1 2 |
mpstat 1 # => mpstat every second |
Memory monitoring
1 |
cat /proc/meminfo |
or
1 |
free |
Empty / free up memory caches
To free pagecache
1 |
echo 1 > sudo /proc/sys/vm/drop_caches |
To free dentries and inodes:
1 |
echo 2 > sudo /proc/sys/vm/drop_caches |
To free pagecache, dentries and inodes:
1 |
echo 3 > sudo /proc/sys/vm/drop_caches |
As this is a non-destructive operation and dirty objects are not freeable, the user should run “sync” first!
loop free memory bash
1 2 |
while true; do free -m; sleep 1; done while :; do free -m; sleep 1; done |
Memory & CPU Utilisation
1 2 3 |
ps -eo pcpu,%mem,cmd|sort -k2 -r ps -eo pcpu,%mem,cmd|sort -k2 -r|head -3 |
1 2 |
top -p <processid1> top -p 20832 |
process id from name
1 |
ps -ef | grep w.py|grep -v grep | awk '{print $2}' |
top for only
1 |
top -p `ps -ef | grep w.py|grep -v grep | awk '{print $2}'` one process by name |
Machine CPU – using ps aux
1 |
while :; do ps aux|awk 'NR > 0 { s +=$3 }; END {print s"%"}'; sleep 1; done |
Process CPU – using ps uax
1 2 |
while :; do ps aux|grep w.py|awk 'NR > 0 { s +=$3 }; END {print s"%"}'; sleep 1; done => very inaccurate |
Process CPU – using top
1 2 |
while :; do top -c -b -n 1|grep w.py; sleep 1; done => this is more accurate |
Even Better!
1 2 3 4 5 |
#while :; do top -c -b -n 1|grep w.py|grep -v grep|awk '{print $10}'; sleep 1; done while :; do top -c -b -n 1|grep w.py|grep -v grep|awk '{print $9}'; sleep 1; done while :; do i=$((i+1)); echo $i ; top -c -b -n 1|grep w.py|grep -v grep|awk '{print $9}'; sleep 1; don |
Load – General
1 |
w|grep load |
Load – Using uptime
1 |
while :; do uptime | awk '{print $10}'; sleep 1; done |
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/bash loadavg=`uptime | awk '{print $10}'` # bash doesn't understand floating point # so convert the number to an interger thisloadavg=`echo $loadavg|awk -F \. '{print $1}'` if [ "$thisloadavg" -ge "2" ]; then echo "Busy - Load Average $loadavg ($thisloadavg) " top -bn 1 else echo "Okay - Load Average $loadavg ($thisloadavg) " fi |
References
1. Website Memory Monitoring: http://freetofeel.com/2011/03/02/server-monitor.html
2. check server load with bash: http://www.linuxquestions.org/questions/programming-9/check-server-load-with-bash-703464/
3. How do I Find Out Linux CPU Utilization: http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
3. How to Find the Most Memory taking process in Ubuntu Linux:
http://www.shibuvarkala.com/2010/06/how-to-find-most-memory-taking-process.html
4. Free page caches http://www.linuxinsight.com/proc_sys_vm_drop_caches.html
5. Memory and CPU utilization process: http://www.unix.com/shell-programming-scripting/65947-memory-cpu-utilization-process.html
6. Checking your server load using bash: http://webigniter.wordpress.com/2011/08/03/checking-your-server-load-using-bash/
7. Output CPU load: http://bashscripts.org/forum/viewtopic.php?f=15&t=1237
8. How to get %CPU usage of a process: http://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-cpu-usage-of-a-process-63726/