Tuesday, November 15, 2016

Using Jstatd

JVisuslVM is useful in profiling your server applications local or remote.  To profile your application, you need to run the jstatd daemon in the server your application is running.  Running jstatd is not as straightforward.  Follow these steps:

1) Create a policy file.  The policy tool is in JAVA_HOME/jre/bin.  Start policytool.exe

2) You need to provide the security policy for the tools.jar.  The tools.jar is usually in JAVA_HOME/lib.  DO NOT GIVE RELATIVE PATH such as $JAVA_HOME/lib/tools.jar.  The jstatd doesn't recognize it.  Instead provide the absolute path.

3) Click "Add Policy Entry" and enter the following in "CodeBase" text box: file:/usr/java/default/lib/tools.jar (for non-windows and also, check your java path in your machine) or "c:/Program Files (x86)/Java/jdk1.7.0_79/lib/tools.jar" (for Windows, for ex.  Use "/" for windows path also).

4) Click "Add Permission" and enter the following in "AllPermission" text box: java.security.AllPermission. Click Ok.

5) Click "Done"

6) Click File->Save and save it.

7) Copy this policy file to the remote server (if needed).

8) Go to $JAVA_HOME/lib folder.

9) Run the following: jstatd -J-Djava.security.policy=/<absolute path to the folder where the policy file is>/<policyfile name> -p1234

Note: The -p option may not  required in some cases and this value is a random value chosen.

Now run the Java VisualVM and Click on Remote and add the remote server name.  You should see  the Jstatd process.


No comments:

Post a Comment