Visualvm monitoring JVM and remote JVM monitoring method ()

Source: Internet
Author: User
Tags visualvm

Visualvm is Sun's openjdk project. It aims to create a complete set of problem solving tools for Java applications. It integrates a visual tool with multiple JDK command tools. It is mainly used to monitor JVM running conditions, you can use it to view and view heap dump, thread dump, memory object instance, GC execution, CPU consumption, and class loading. Java developers can use visualvm to create logs of required information. System Administrators can monitor and control the running status of Java applications on the network.
Download Page: https://visualvm.dev.java.net/download.html

Document address: https://visualvm.dev.java.net/docindex.html

Getting started with https://visualvm.dev.java.net/zh_CN/gettingstarted.html

Install plug-ins
By installing the plug-in provided by the visualvm update center, you can add functions to the visualvm.
1. Select "Tools"> "ins" from the main menu ".
2. In the "available plug-ins" tab, select the "Install" check box for the plug-in. Click Install ".
3. Install the plug-in gradually.


Function
1. Overview
View JVM information and system configuration


2. Monitoring
Measure the test taker's understanding about the project sports.


3. Visual GC
The memory GC details are displayed.


Remote Monitoring
1. Start the RMI service through jstatd
Configure Java security access and save the following code as the file jstatd. All. Policy and put it in java_home/bin. The content is as follows,
Grant codebase "file: $ {java. Home}/../lib/tools. Jar "{

Permission java. Security. allpermission;

};

Run the command jstatd-J-Djava.security.policy = jstatd. All. Policy-J-Djava.rmi.server.hostname = 192.168.1.8 & (192.168.1.8 is the IP address of your server, & indicates running as a daemon)
Jstatd command explanation: http://hzl7652.iteye.com/blog/1183182

Open jvisualvm, right-click remort, and select "add remort host...". In the pop-up box, enter your remote IP address, for example, 192.168.1.8. The connection is successful.

2. Configure JMX to manage Tomcat
Open the bin/Catalina. BAT file of Tomcat. If it is a Linux or UNIX system, it is the Catalina. Sh file.
Unlimited access

Set java_opts =-DCOM. sun. management. jmxremote-DCOM. sun. management. jmxremote. port = 9008-DCOM. sun. management. jmxremote. authenticate = false-DCOM. sun. management. jmxremote. SSL = false

Access java_opts = '-xms128m-xmx256m-XX: maxpermsize = 128 M-djava. RMI. server. hostname = 192.168.1.8-DCOM. sun. management. jmxremote. port = 8088-DCOM. sun. management. jmxremote. SSL = false-DCOM. sun. management. jmxremote. authenticate = true-DCOM. sun. management. jmxremote. password. file =/usr/Java/default/JRE/lib/management/jmxremote. password-DCOM. sun. management. jmxremote. access. file =/usr/Java/default/JRE/lib/management/jmxremote. access'

(Jmxremote. Access has a template under java_home \ JRE \ Lib \ management)
Display in jmxremote. Access
Monitorrole readonly

Controlrole readwrite


Display in jmxremote. Password
Monitorrole QED (QED is the password)

Controlrole R & D

Re-Open remote tomcat in visualvm can use the features of JMX http://www.blogjava.net/titanaly/archive/2012/03/20/372318.html from the left application tree can know, not only can monitor the local JVM running, you can also monitor the JVM running status on a remote machine.
Local monitoring: a Java program is automatically added to local monitoring.

Because local monitoring does not need to be configured, this section mainly introduces remote JVM monitoring.
To perform remote monitoring, the local visual VM must communicate with the remote JVM. Currently, visual VM supports two remote connection methods.
Jstatd and JMX Methods: Here I mainly introduce the JMX method.

To connect to a remote machine through JMX, the following configuration is required:
1. Modify the JDK configuration file of the remote machine (I use Linux as the remote machine ).
A. Go to the java_home \ JRE \ Lib \ management \ directory.
B. Copy the jmxremote. Password. template file to the current directory and change it to jmxremote. Password.
C. Open the jmxremote. Password File and remove the comments before # monitorrole QED and # controlrole R & D.

2. modify the configuration file of the program to be monitored on the remote machine (I am monitoring the application deployed in the Tomcat container ).
A. Go to the atat_home \ bin directory.
B. Open the Catalina. Sh file and add the following information:
Java_opts = "$ java_opts-djava. RMI. server. hostname = 192.168.0.237
-DCOM. Sun. Management. JMX remote. Port = 18999
-DCOM. Sun. Management. jmxremote. SSL = false
-DCOM. Sun. Management. jmxremote. Authenticate = false"
C. Restart the Tomcat service.

3. Client visualvm configuration (my client uses WINXP ).
A. Click remote and select add remote host...
B. Enter the IP address of the remote machine (192.168.0.237) in the pop-up interface. The IP address will be added to the remote node.
C. Click the IP address and select Add JMX connection. On the displayed page, enter the configured port number (18999). The connection will be added to the IP node.
D. Click the link and select open.

Now we can see the monitoring interface, from the interface we can see the CPU information, memory information, statistics of the number of loaded classes, thread information. http://blog.163.com/liuyb_94242/blog/static/42167646201210131156174/ jstatd [Options]


This command is an RMI server application that provides JVM creation and termination monitoring, and also provides an attach interface for remote monitoring tools.

Options
-Nr: When an existing RMI registry is not found, an internal RMI registry is not created.
-P port number. The default value is 1099.
-N rminame: jstatremotehost by default. If multiple jstatd services start on the same host, rminame uniquely identifies a jstatd service.
-J jvm options

Jstatd
The following error is reported:

Cocould 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: 323) at java. security. accesscontroller. checkpermission (accesscontroller. java: 546) at java. lang. securitymanager. checkpermission (securitymanager. java: 532) at java. lang. system. setproperty (system. java: 727) at Sun. tools. jstatd. jstatd. main (jstatd. java: 122)

 
This is because no security policy is specified for jstatd.

Create a security policy file and name it jstatd. All. Policy
Grant codebase "file: $ {java. Home}/../lib/tools. Jar "{
Permission java. Security. allpermission;
};

Start again
C: \ Program Files \ Java \ jdk1.6.0 _ 16 \ bin> jstatd-J-Djava.security.policy = jstatd. All. Policy


Use JPs to view running Java commands
JPS

C: \ Documents ents and Settings \ Lulu> JPs
4892 Bootstrap
Jstatd 1296
JPS 4484
3332 org. Eclipse. Equinox. launcher_1.0.201.r35x_v20090715.jar

 

Then, you can use jvisualvm.exe to remotely monitor JVM information.

More examples

(1) Use the internal RMI Registry
Jstatd-J-Djava.security.policy = all. Policy (default port: 1099)
(2) Use external RMI Registry
A) use the default value
Rmiregistry &
Jstatd-J-Djava.security.policy = all. Policy
B) use port 2020
Rmiregistry 2020 &
Jstatd-J-Djava.security.policy = all. Policy-P 2020
C) use port 2020 and rminame
Rmiregistry 2020 &
Jstatd-J-Djava.security.policy = all. Policy-P 2020-N alternatejstatdservername
(3) RMI registry has been started, and internal RMI registry is not created
Jstatd-J-Djava.security.policy = all. Policy-NR
(4) RMI log capability
Jstatd-J-Djava.security.policy = all. Policy-J-Djava.rmi.server.logCalls = true

Http://hzl7652.iteye.com/blog/1183182

 

Visualvm monitoring JVM and remote JVM monitoring method ()

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.