Saturday, September 12, 2015

monitoring remotely with jvisualvm and jstatd

If you run jstatd on a machine, you will get:

could not create remote object
access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses" "write")
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses" "write")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
        at java.security.AccessController.checkPermission(AccessController.java:559)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.System.setProperty(System.java:783)
        at sun.tools.jstatd.Jstatd.main(Jstatd.java:139)



So, create a jstatd.policy file and enter:
grant codebase "file:D:/pierre/Java/jdk1.7.0_79/lib/tools.jar" {
permission java.security.AllPermission;
};


(full documentation of policy files here )

then run "jstatd -J-Djava.security.policy=jstatd.policy"

Now in jvisualvm you can add remote host, then right-click on the host, "add jstatd connection" and this will connect to the default 1099 port on remote host (it's a RMI server, so it uses the default RMI port)

use "jps " from your local machine to check that the jstatd is actually reachable.

See also http://www.nljug.org/nieuws/blog-profiling-remote-jvm-using-visualvm/ for a more complete list of options. Particularly useful the -p option and the -J-Djava.rmi.server.hostname=x.x.x.x .

No comments: