Using VISUALVM to monitor the remote server JVM

Source: Internet
Author: User
Tags visualvm

The VISUALVM is an all-in-one performance monitoring and failure analysis tool from the JDK, including CPU usage, JVM heap memory consumption, real-time monitoring of threads, class loading, memory dump file analysis, and visual analysis of garbage collection operations, which is helpful for troubleshooting and performance tuning. After installing the JDK in Windows, VISUALVM is located under%java_home%/bin/and executes the Jvisualvm.exe directly, a main operating interface


VISUALVM will automatically detect the JVM in the native running and establish a connection, this article mainly introduces the configuration method of connecting the remote Linux server, the test environment is CentOS 6.5,JDK8,TOMCAT8.

VISUALVM There are two ways to connect to a remote server: JMX and jstatd, neither of which can perfectly support all features, such as JMX does not support VISUALGC,JSTATD does not support CPU monitoring, the actual use can be configured simultaneously and on-demand.

1 Pre-configuration preparation

We need to check the linux hostname matching IP first, execute

Hostname-i

If the matching result is unrecognized or 127.0.0.1, you will need to manually configure the hostname and IP mapping. Suppose the IP to be used to establish the connection is 192.168.11.233, and the hostname is mylinux:

Vi/etc/hosts

Add a row

192.168.11.233 Mylinux

2 Configuring JMX2.1 Create setenv.sh

Enter the Tomcat/bin directory

VI setenv.sh

#!/bin/shexport java_opts= "$JAVA _opts-xms512m-xmx512m-dcom.sun.management.jmxremote.ssl=false- Dcom.sun.management.jmxremote.password.file=. /conf/jmxremote.password-dcom.sun.management.jmxremote.access.file=. /conf/jmxremote.access "
(-xms512m-xmx512m is not a required parameter, it is just a hint that can be adjusted together with the JVM parameters)

Set permissions

chmod +x setenv.sh

2.2 Adding listener to Server.xml

Enter the tomcat/conf directory

VI Server.xml

<listener classname= "Org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiregistryportplatform= "10001" rmiserverportplatform= "10002"/>

The port can be modified according to the actual situation, after the added structure such as

2.3 Jmx Access Control files

Enter the tomcat/conf directory and execute

CP $JAVA _home/jre/lib/management/jmxremote.password.template JMXREMOTE.PASSWORDCP $JAVA _home/jre/lib/management/ Jmxremote.access jmxremote.access

And then

VI Jmxremote.password

Uncomment the following two lines
#monitorRole QED
#controlRole

You can also customize your account by adding a line in the format username password, so you need to modify the Jmxremote.access

VI jxmremote.access
At the bottom of the add
Username ReadWrite

Modify Permissions

chmod Jmxremote.password
chmod jxmremote.access

2.4 Adding Catalina-jmx-remote.jar

Http://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina-jmx-remote

Copy to tomcat/lib directory after download

At this point, the configuration work is complete, but you also need to add two ports in 2.2 to the firewall allow rule

2.5 Setting up a firewall

Vi/etc/sysconfig/iptables

Join before a input-j REJECT--reject-with icmp-host-prohibited

-A input-p tcp-m state--state new-m TCP--dport 10001-j accept-a input-p tcp-m State--state new-m TCP--dport 10 002-j ACCEPT
Service Iptables Restart

Telnet the server's 10001 and 10002 ports on the client, if it is correct.

2.6 Testing

Start Jvisualvm.exe on the client, add remote host on the left side of the tree menu remotely, and host name fill in server IP


After determining, a new child node appears under the remote, and the JMX connection is added right-click on the child node

Connect the input ip:10001, and note that this port is the Rmiregistryport configured in 2.2 steps. Check the use of security credentials, user name and password is 2.3 steps in the Jmxremote.password file in the user name and corresponding password. Tick Save security credentials


SSL is not enabled in the configuration of this article, and when you click OK, you are prompted to confirm that you are not trying to connect using SSL, and select Yes. If everything goes well. A JMX connection subnode appears under the server node, and the feature interface opens after double-clicking.


Try a powerful visual GC plugin, unfortunately, "not supported by this JVM", if you want to use this plug-in, you need to configure the JSTATD connection method, the following jstatd configuration.

3 Configuring the jstatd3.1 configuration Security Policy VI $JAVA _home/jre/lib/security/java.policy
At the bottom of the file}; Before adding
Permission java.security.AllPermission;

3.2 Starting JSTATDCD $JAVA _home/bin
./jstatd-j-djava.security.policy=all.policy &
After startup, registration port 1099 and a random connection port are turned on, and the registration port can also be specified by the-p parameter, such as./jstatd-j-djava.security.policy=all.policy-p 10003 & 3.3 Setting up a firewall in addition to adding 1099 to the firewall rules, you also need to find another random port and join the rule to execute NETSTAT-ANP | grep *jstatd

You can see that in addition to the 1099,JSTATD also listen to the 53040 port, add this to the rule, adding the method reference 2.5 (Note: This random port will change after the restart) 3.4 test boot VISUALVM, because when the JMX was configured to add the server node, if configured correctly, Typically VISUALVM automatically detects JSTATD connections and adds nodes
If there is no auto-add, you can check if the port is connected and try to manually add the connection VISUALGC interface
Finish

Using VISUALVM to monitor the remote server JVM

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.