Monday, February 16, 2009

Nice little shell script to trace memory occupation of Weblogic processes

this script was provided by the generosity of Mark van Holsteijn www.xebia.com , a man with strong brain muscles.

showWebLogic.sh

#!/bin/bash

#!/bin/bash

echo "pid minheap maxheap vsize residnt share text data name jvm"
ps -ef | grep java | grep -v grep | while read LINE
do
        MINHEAP=$(echo $LINE | sed 's/.*-Xms\([^ ]*\).*/\1/')
        MAXHEAP=$(echo $LINE | sed 's/.*-Xmx\([^ ]*\).*/\1/')
        PID=$(echo $LINE | awk '{print $2}')
        JVM=$(echo $LINE | awk '{print $8}')

        NAME=$(echo $LINE | sed -n -e 's/.*-Dweblogic.Name=\([^ ]*\).*/\1/p')
        if [ -z "$NAME" ] ; then
                NAME=$(echo $LINE | sed -n -e 's/.*weblogic.\(NodeManager\).*/\1/p')
        fi
        if [ -z "$NAME" ] ; then
                NAME="UnknownApp"
        fi
        cat /proc/$PID/statm | \
        awk -vpid=$PID \
        -vjvm="$JVM" \
        -vname="$NAME" \
        -vminheap=$MINHEAP \
        -vmaxheap=$MAXHEAP \
        '{ printf ("%ld\t%s\t%s\t%ldmb\t%ldmb\t%ldmb\t%ldmb\t%ldmb\t%s\t%s\n",
        pid, minheap, maxheap,
        ($1 * 4) / 1024,
        ($2 * 4) / 1024,
        ($3 * 4) / 1024,
        $(4 * 4)/1024, ($6 * 4)/1024, name, jvm); }'

done







the output is:

pid minheap maxheap vsize residnt share text data name jvm

6811 128m 256m 1473mb 169mb 3mb 0mb 1391mb NodeManager /opt/bea/jrockit/R27.3.1/bin/java

8289 512m 512m 2060mb 903mb 4mb 0mb 1962mb pierre_dev_eb_alsb_admin_server java

9893 1024m 1024m 2474mb 1300mb 3mb 0mb 2383mb pierre_dev_eb_alsb_server_1 /opt/bea/jrockit/R27.3.1/bin/java


1 comment:

Mark van Holsteijn said...
This comment has been removed by the author.