, ,

Unix – Process and Load monitoring in Linux

wmstat

vmstat 1

htop

Installation

sudo apt-get install -y htop
sudo htop

atop

Installation

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

ps aux | sort -nrk 4 | head

Sysstat

Installation

sudo apt-get install -y  sysstat

mpstat -> contained in sysstat

mpstat 1
# => mpstat every second

Memory monitoring

cat /proc/meminfo

or

free

Empty / free up memory caches
To free pagecache

echo 1 > sudo /proc/sys/vm/drop_caches

To free dentries and inodes:

echo 2 > sudo /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

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

while true; do free -m; sleep 1; done
while :; do free -m; sleep 1; done

Memory & CPU Utilisation

ps -eo pcpu,%mem,cmd|sort -k2 -r

ps -eo pcpu,%mem,cmd|sort -k2 -r|head -3
top -p 
top -p 20832

process id from name

ps -ef | grep w.py|grep -v grep | awk '{print $2}'

top for only

top -p `ps -ef | grep w.py|grep -v grep | awk '{print $2}'` one process by name

Machine CPU – using ps aux

while :; do ps aux|awk 'NR > 0 { s +=$3 }; END {print s"%"}'; sleep 1; done

Process CPU – using ps uax

while :; do ps aux|grep w.py|awk 'NR > 0 { s +=$3 }; END {print s"%"}'; sleep 1; done
=> very inaccurate

Process CPU – using top

while :; do top -c -b -n 1|grep w.py; sleep 1; done
=> this is more accurate

Even Better!

#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

w|grep load

Load – Using uptime

while :; do uptime | awk '{print $10}'; sleep 1; done
#!/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/


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *