VMSTAT
1 |
vmstat 1 |
htop
1 2 |
sudo apt-get install -y htop sudo htop |
atop
1 2 |
sudo apt-get install atop -y 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.
Open a terminal and Type the following command
1 |
ps aux | sort -nrk 4 | head |
Sysstat
1 |
sudo apt-get install sysstat -y |
mpstat -> contained in sysstat
1 |
mpstat 1 => mpstat every second |
Memory monitoring of a give Process
1 |
cat /proc/meminfo |
System memory allocation
1 2 3 4 5 6 7 |
free <pre> <h1>empty / free up memory caches</h1> <h1>To free pagecache:</h1> <pre class="theme:classic toolbar:2 nums:false plain:false scroll:true lang:bash decode:true"> 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!
This was originally found @ http://www.linuxinsight.com/proc_sys_vm_drop_caches.html
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 |
See also http://www.unix.com/shell-programming-scripting/65947-memory-cpu-utilization-process.html
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 |
See also: http://bashscripts.org/forum/viewtopic.php?f=15&t=1237 and http://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-cpu-usage-of-a-process-63726/
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 |
Checking your server load using bash
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. http://www.linuxquestions.org/questions/programming-9/check-server-load-with-bash-703464/
2. http://freetofeel.com/page3/
3. http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
4. http://www.shibuvarkala.com/2010/06/how-to-find-most-memory-taking-process.html