Use JVISUALVM to monitor local and remote JVMs

Source: Internet
Author: User

The JVISUALVM is a visual monitoring tool that comes with the JDK and is powerful and can be installed with a variety of extensions. This article is not intended to explain if you use verbose functionality, just talk about the Java process in the Windows environment How to monitor both local and remote (typically non-interface Linux systems).

1. Add the rights policy file on the remote machine

Set up file in server {Java_home}/bin directory: Jstatd.all.policy (name is random, match *.policy), file content is:

grant codebase "file:${java.home}/../lib/tools.jar" {        permission java.security.AllPermission;    };    

2. Modify the IP address in the server Hosts file

For the Java VisualVM to successfully connect to the remote server, the server side should set the native address to the IP address of the native in the/etc/hosts file. Use the Hostname-i command to view, if the display is 127.0.0.1 or inconsistent with the native IP, you need to change the corresponding address in the/etc/hosts file to the native real IP.

3. Running the JSTATD daemon

Running in jstatd.all.policy current directory

nohup $JAVA_HOME/bin/jstatd -J-Djava.security.policy=jstatd.all.policy &

If you need the RMI logging function, you can also add-j-djava.rmi.server.logcalls=true to the startup parameters.

nohup $JAVA_HOME/bin/jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.logCalls=true &

You can make your own jstatd port, add-p <port> parameters, the default port is 1099.

I wiped it, and I made an error

Could not bind/jstatremotehost to RMI Registry java.rmi.ServerException:RemoteException occurred in server thread; Nested exception is:java.rmi.UnmarshalException:error unmarshalling arguments;  Nested exception Is:java.lang.ClassNotFoundException:sun.jvmstat.monitor.remote.RemoteHost (no security Manager: RmiClassLoaderDisabledAtSun.Rmi.Server.Unicastserverref.Olddispatch (Unicastserverref.java:419)AtSun.Rmi.Server.Unicastserverref.DispatchUnicastserverref.java:267)AtSun.Rmi.Transport.Transport$1.RunTransport.java:177)AtSun.Rmi.Transport.Transport$1.RunTransport.java:174)AtJava.Security.Accesscontroller.Doprivileged (NativeMethod)AtSun.Rmi.Transport.Transport.ServiceCall (Transport.java:173)AtSun.Rmi.Transport.Tcp.Tcptransport.Handlemessages (Tcptransport.java:553)AtSun.Rmi.Transport.Tcp.tcptransport$Connectionhandler.Run0 (Tcptransport.java:808)AtSun.Rmi.Transport.Tcp.tcptransport$Connectionhandler.RunTcptransport.java:667)AtJava.Util.Concurrent.Threadpoolexecutor.Runworker (Threadpoolexecutor.java:1145)AtJava.Util.Concurrent.threadpoolexecutor$Worker.RunThreadpoolexecutor.java:615)AtJava.Lang.Thread.RunThread.java:722)AtSun.Rmi.Transport.Streamremotecall.Exceptionreceivedfromserver (Streamremotecall.java:273)AtSun.Rmi.Transport.Streamremotecall.Executecall (Streamremotecall.java:251)AtSun.Rmi.Server.Unicastref.InvokeUnicastref.java:377)AtSun.Rmi.Registry.Registryimpl_stub.RebindUnknownSource)at java. Rmi. naming. rebind (naming. java:177)         at  sun. tools. jstatd. jstatd. bind (jstatd. java:57)         at  sun. tools. jstatd. jstatd. main (jstatd. java:143)               

Don't worry, this error is your port is occupied, jstatd default boot 1099 port, using NETSTAT-ANP | grep 1099 to see if the port is occupied! If it is used for a different port.

jstatd -J-Djava.security.policy=jstatd.all.policy -p 2099

4. Connect a remote host using a local JVISUALVM

In the 1, 2, 3 steps, finally we use window local JVISUALVM connection configured remote host, this is very simple, not introduced.

But here's the problem, 3rd. Connection configuration But how can not see the remote machine Java process, troubleshooting this problem, please determine whether your step success

(1) service-side machine JSTATD service is turned on: Use JPS to see if there is a jstatd process.

(2) Determine if the local machine is connected to a remote server, using NETSTAT-ANP | grep jstatd Process ID View network connection, whether there is your local machine IP

Configure and start JVISUALVM

Direct command line to start the JVISUALVM or {Java_home}/bin directory, locate the Jvisualvm.exe program, double-click Open.

If the JSTATD port is re-specified, select Advanced settings to modify the port, such as:

Connecting to the server in the above way discovers a problem and cannot monitor the CPU. Prompts us to establish JMX, to establish JMX hint request port number. (Jmx:java Management Extensions, the Java management extension, is a framework for embedding management functions for applications, devices, systems, and so on. JMX can flexibly develop seamlessly integrated systems, network, and service management applications across a range of heterogeneous operating system platforms, system architectures, and network transport protocols. Visual VMs are connected to remote Java applications through JMX.

5. JVM Process Startup item configuration

Take Tomcat for example:

The server's Tomcat configures the JVM startup parameters. Add the following parameters to Tomcat's catalina.sh:

JAVA_OPTS="-Djava.rmi.server.hostname=192.168.0.216 -Dcom.sun.management.jmxremote.port=1100 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
注:-Dcom.sun.management.jmxremote.port :1100 这个是配置远程 connection 的端口号的,要确定这个端口没有被占用-Dcom.sun.management.jmxremote.ssl=false   指定了 JMX 是否启用 ssl-Dcom.sun.management.jmxremote.authenticate=false   指定了JMX 是否启用鉴权(需要用户名,密码鉴权)前面是固定配置,是 JMX 的远程服务权限的-Djava.rmi.server.hostname :这个是配置 server 的 IP 的

If you configure JMX at the same time, you can add JMX connections such as:

After adding:

This article was reproduced from: http://ihuangweiwei.iteye.com/blog/1219302

Using JVISUALVM to monitor local and remote JVMs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.