Afficher la RAM des process les plus consommateurs

Voici comment afficher la liste des 10 processus les plus consommateurs et la RAM utilisée par ces derniers.

# ps -eo size,pid,user,command | sort -rn | head -10 | awk '{hr[1024**2]="GB"; hr[1024]="MB";for (x=1024**3; x>=1024; x/=1024) {if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break }} } { printf ("%-6s %-10s ", $2, $3) }{ for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'
5.64   GB 28817  mysql      /apps/mysql/cluster-7.4.11/bin/ndbd --ndb-connectstring=vl-d-pxx-12:1186,vl-d-pxx-26:1186 --ndb-nodeid=2 --foreground=true
2.34   GB 2000   mysql      mysql-monitor-agent -java-home /apps/mysql/memagent/java -server -Xms32m -Xmx64m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/apps/mysql/memagent/logs/mysql-monitor-agent.hprof -XX:OnOutOfMemoryError=/apps/mysql/memagent/bin/agentRestart.sh -user mysql -pidfile /apps/mysql/memagent/mysql-monitor-agent.pid -wait 90 -outfile /apps/mysql/memagent/logs/mysql-monitor-agent.stdout -errfile /apps/mysql/memagent/logs/mysql-monitor-agent.stderr -classpath /apps/mysql/memagent/bin/bootstrap:/apps/mysql/memagent/lib/commons-daemon-1.0.10.jar -DMYSQL_AGENT_HOME=/apps/mysql/memagent -Djava.library.path=/apps/mysql/memagent/lib -showversion -procname mysql-monitor-agent com.mysql.etools.agent.runtime.Bootstrap --agent-instance-dir=/apps/mysql/memagent
1.15   GB 14832  root       python /usr/bin/goferd
1.05   GB 2582   root       /apps/ITM/lx8266/lz/bin/klzagent
465.77 MB 1948   mysql      /apps/mysql/mcm/libexec/mcmd --plugin-dir=/apps/mysql/mcm/lib/mcmd --defaults-file=/apps/mysql/mcm/etc/mcmd.ini --daemon --pid-file=/apps/mysql/mcm/mcmd.pid
397.02 MB 4054   root       /apps/ITM/lx8266/lz/bin/kcawd
370.44 MB 1660   root       /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
102.05 MB 3685   root       /usr/IBM/TWA/00svczc1/TWS/bin/JobManager
49.28  MB 15067  root       sort -rn
22.54  MB 1738   root       /apps/tad4d/lmt/tlmagent.bin

EDIT: Deux autres commandes glanées auprès des collègues :

find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -hr | head | cut -d " " -f2-

La même avec le pourcentage à présent

find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" -v TOTSWP="$(cat /proc/meminfo | sed  -n -e "s/^SwapTotal:[ ]*\([0-9]*\) kB/\1/p")" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") {used_swap=process["VmSwap"];sub(/[ a-zA-Z]+/,"",used_swap);percent=(used_swap/TOTSWP*100); printf "%10s %-30s %20s %6.2f%\n",process["Pid"],process["Name"],process["VmSwap"],percent} }' '{}' \;  | awk '{print $(NF-2),$0}' | sort -hr | head | cut -d " " -f2-

Sources:

  • http://php.ingewikkeld.net/entry/human-readable-memory-usage-in-linux-per-process
  • http://www.linuxquestions.org/questions/programming-9/how-to-show-the-top-processes-eating-ram-in-human-readable-826216/

Ajouter un commentaire

Les commentaires peuvent être formatés en utilisant une syntaxe wiki simplifiée.

La discussion continue ailleurs

URL de rétrolien : http://blog.tools-fm.com/index.php?trackback/234

Fil des commentaires de ce billet