Saturday, April 10, 2010

Monitoring Java Virtual Machines

Apart of the default consoles that are delivered with the Oracle product; such as Weblogic Console, BPEL console, ESB Console, Enterprise Manager. We can also look 'under the hood' of the application server.

With the latest release of WebLogic, you proberly use Oracle JRockit as JVM. This JVM has its own console, JRockit Mission Control. If you are not using JRockit, because you are using another OS such HP or IBM, or you just stick to the Oracle/SUN JDK, then the following solution will help. A nice article is published by Olaf Heimburger describing both tools based on the 11g release.

Monitoring the behavior of the JVM can be done via the tool 'VisualVM'. The tool can be used directly on Java VM that are running on your local machine. By default it can connect to JVM's of version 1.6. If you are using a JVM of version 1.5 you should at the following Java properties during the startup.

The tool is able to connect to local JVM's as well remote JVM's. Connecting to a remote JVM, a daemon process must be running on the server to collect the data from the JVM and expose this for client applications.

Server Configuration


WLS 9.2 only

The Java parameters can be set in the arguments settings for each managed server.

Add the following Java option into the WLS 9.2 managed servers:

-Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false


After applying the Java settings, restart the managed server.

Create in the JAVA_HOME directory a policy file, that grants all permissions to the Java Statistic daemon process.

JAVA_HOME=/u01/appl/j1bplpe/product/wls/jdk150_12
export $JAVA_HOME

cd $JAVA_HOME/bin
vi jstatd.policy:
grant codebase "file:${java.home}/../lib/tools.jar" {
  permission java.security.AllPermission;
};

Now we can start the daemon process to collect the java runtime statitics.

Generic

The Jstat daemon process can now be started. In the next example it is started 'online'. I would recommend this, this process should not be running during normal production. Otherwise start the programm with 'nohup' and '&'.

cd $JAVA_HOME/bin
./jstatd -J-Djava.security.policy=jstatd.policy -p 1099

The daemon process is started, it connect to the JMX port 3333 and can be accessed with 'VisualVM' over port 1099 without having credentials or SSL.

Unix start script
cat start_jstatd.sh
#!/bin/bash

start_jstatd.sh
JAVA_HOME=/usr/lib/jvm/sun-java-1.6
export JAVA_HOME
nohup $JAVA_HOME/bin/jstatd -J-Djava.security.policy=./jstatd.policy -p 1099  &
echo $! > jstatd.pid
echo Java Stats Deamon started: `cat jstatd.pid`

stop_jstatd.sh
#!/bin/bash

JAVA_HOME=/usr/lib/jvm/sun-java-1.6
export JAVA_HOME

if [ -f "jstatd.pid" ];
then
  pid=`cat jstatd.pid`
  echo "killing jstatd with pid $pid"
  kill -9 $pid
else
  kill -9 `ps -ef | grep "jstatd" | grep -v grep | awk '{ print $2; }'`
fi

Client Configuration

At the client side, download the code latest version visualVM, this can be obtained from:

http://visualvm.dev.java.net

Unzip the ZIP file into a directory. In this directory you can start the the client tool to visualize the JVM. If Java 1.6 is installed on your workstation, the settings are already correct and we can start the application.

Linux:
        ./visualvm

Windows:
        visualvm.exe

The screen look like this.


Create a new Remote connection to the server you want. In this case we connect to the node #1 of my cluster via port 1099. This is the port number on which the jstatd daemon is listening.

Select the appropiate JVM, weblogic.Server., to view memory and thread information.


Garbage collection:



More information and documentation on this tool can be obtained via the website.

Post a Comment