Sunday, March 16, 2014

WebLogic Server name its PID, CPU, MEM

I am on a 'THINKING CHAIR' again, thinking to find the fine chopped shell script for displaying process id on the opposite to it the WebLogic(java process) instance name. This is the regular need for any WebLogic Administrator.

1. Some times the Thread counts monitoring cannot help to know the status of the Server instance then need to look for the instance is alive or not. That is the java process exist for that particular instance.
2. You may get Stuck Thread alert for any machine through your monitoring tools (HP OVO, Introscope or some other). Then you need to get the thread dump for the stuck thread found WebLogic instance.
3. You may want to kill an instance for any abnormal reasons

What is 'ps' command does?

The 'ps' command gives us information about processes status on Solaris or Linux or any other UNIX flavor.  There are different varieties of 'ps' command paths
i) /usr/bin/ps
ii) /usr/ucb/ps

If you type “ps” at the prompt, and you get very little information about the process.

ps command switches

The ps command switches are key, as always required to get the desired output of ps command. To get a complete list, for instance, type switches with prefix - symbol.

  • “ps -A” (Note: Linux is case-sensitive). Also, 
  • “ps -e” will give you a complete list of processes running on the machine. 
  • "ps -f" give a full listing, i.e. more information about each process listed 
  • "ps -u username" will list all processes running by a specific user mentioned as argument value
  • "ps  -l" gives a long listing of processes. This is even long data than in a full listing

The power to this 'ps' command will be filled up with its options, If you know how to use the options you can make wonders!! Now I need to know what are those options which could help me to write the script. You tell me what to do? Well your answer is go to our super duper search engine 'Google'.  ps(1B) man page on Oracle sun site. I selected -a, -ww, -x options that could help me to get complete command details of a process id associated with it.

Now I need to use 'cut' command for the WebLogic instance name from the big process detailed text. This is really challenge dear, what you suggest dear super reader? After running between many sites and man pages I got to know few ideas on awk and its family nawk command script.

This script is a generic script I had executed for WebLogic 9.2, 11g also. You can apply this for WebLgoic 7/8.1 also.

# FileName: 
# This script will Fetches PID of WebLogic Server instances 
# =========================================================
echo "PID associated with WebLogic instances"
echo  "====================================="
/usr/ucb/ps -awwx | grep "weblogic.Name" | grep -v "grep weblogic.Name" | nawk 'BEGIN {print "PID\tWLServer";
print  "=====================================" } ;
        NUM = match($0, "weblogic.Name=") ;
        START_STR = substr($0, START_POS) ;
        FINISH = match(START_STR, " ") ;
        FINISH_STR = substr($0, START_POS, FINISH_POS) ;
        NUM = split(FINISH_STR,FINISH_ARRAY) ;
        printf ("%s\t%s\n",$1, FINISH_ARRAY[1]) ;
        END {
        print "===================================="}'

#=== Published on  ===== 

The above script is executed on Solaris 9, 10 the output will look like as follows:
PID associated with WebLogic instances
PID     WLServer
1354    admin
11469   mserver01
11581   mserver02


Similar type of script is required for Linux machines too. Then I need to change the above script in 3 places.

The ps command options, Linux supports gawk (GNU awk) instead of nawk. The final thing to change is the string that requires not to grep useless string.

Perl for WebLogic on Linux
With the ps command we can get the desired output onto standard output. Perl having great Match, split built-in functions. In Linkedin Perl group, I followed Ashutosh Kukreti tips. You must be member so that you can see the discussion. I had posted the question about my requirement. After looking into Perl regular expressions usage.

$plist = `ps -U \$LOGNAME -o pid,pcpu,size,cmd|grep -i weblogic.Name|egrep -v grep`;
@prlist = split(/\n/ ,$plist );
print "PID    SERVER          CPU     SIZE      DOMAIN DIR
------ --------------- ------ ------  -----------------------------------
foreach $_ (@prlist){
        $x=~ m/^\s*(\d+)\s.+\s+-Dweblogic\.Name=(\S+)\s+/ ||next;
        my @values = split(' ',$x);
        if($cpu > $CPU_THRESHOLD)
                print "\n\nSUGGESTED ACTION:\n"
                        . "-----------------\n"
                        . "Use this command to trace threads on servers "
                        . "with over $CPU_THRESHOLD% CPU usage:\n"
                        . "/usr/bin/kill -3 " . $pid;
        $r = `/usr/bin/pwdx $pid 2>&1`;
        $r =~ s/^\d+://;
        $r =~ s/^\s+|\s$//g;
        print $pid, "\t", $server,"\t",$cpu,"\t",$mem,"M\t",$r,"\n";
This part of Perl script, my friend SRIKANTH PANDA helped me to get process id and its related info with ps command.

Here in this script you can set your application desired CPU_THRESHOLD value to get notifying mails. After saving the file provide the execution permissions with chmod u+X The following is the output which I've executed on Ubuntu Linux with WebLogic 12c.

$ ./
PID    SERVER          CPU     SIZE      DOMAIN DIR
------ --------------- ------ ------  -----------------------------------
2518 AdminServer 2.8 860M /home/pavanwla/wlsdomains/medrec

Enjoy the fun with scripting tricks on your latest WebLogic environments, keep posting your updates and thoughts on this blog. Share this blog in your technical blogs.


  1. You can get the process id's with this command too jps -l

  2. Yes! dude jps is wonderful command I have already explored it. here my intention is to get WebLogic server name along with process id and also its cpu load, memory occupied by the instance.

  3. it is showing this too , i m not sure where to change the script . output on my system -
    Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
    AdminServer 2351
    ManagedServer_1 2453
    ") 6306
    AdminServer-TRAIN 22808

  4. Pavan Good script :) was useful for me

    Hi Anonymous,

    For Removing,

    Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ

    Remove -awwx and put only awwx from the below lines

    /usr/ucb/ps -awwx | grep "weblogic.Name" | grep -v "grep weblogic.Name" | nawk 'BEGIN {} ;

  5. hi, I am new to weblogic. Can u give some linux commands, which are commonly used in weblogic?

  6. Hi Jyothi,
    Thanks for visiting the blog, appreciate for your comments. We are in process of collecting all basic commands that can be applied for WebLogic and middleware administration purpose only. We have published three exclusive pages Unix Tips 1, 2, 3 in "Middleware Admin" site. Please visit the "".

  7. Hi, thanks for ur reply.. Are dere any back up tools other than commands like tar, cp...?

  8. The perlscript is great (nice idea to use pwdx to determine domain) but does only work when you have two servers running (for example 1 admin and 1 managed server). I have an user which "runs" two domains, each of them with two servers (so overall 2 admin and 2 managed servers) and the script does only show two servers of one domain. Unfortunately, I can't figure out what goes wrong in the script by myself. When increasing the $i to 3 before the foreach, it shows the other two servers.

  9. Dear Pavan,
    Thnx for the script, Im able to run the script after few modifications, I've tested it in RHEL 5, as end user.
    ps is not thr at /usr/ucb/, im able to find it in /bin dir.
    nawk didn't work for me but able to get the output with awk.
    great job, keep it up !!


Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me