jvisualvm (Java VisualVM)

Article source: https://blog.csdn.net/a19881029/article/details/8432368

What can jvisualvm do

Monitor memory leaks, track garbage collection, execute memory, cpu analysis, thread analysis...

 

jvisualvmg has been integrated in the version above jdk1.6 (not jre). The minimum jdk1.6 version is required for its own operation, but java programs running on jdk1.4 or higher can be monitored

Take jdk1.6update45 (jvisualvm that comes with jdk1.6update45) as an explanation. Of course, you can also download a separate jvisualvm separately. After the jdk is installed normally, go to the jdk bin directory and run jvisualvm.exe.

Some people on the Internet say that jvisualvm does not support the ntfs hard disk format (all said that it is not good, and did not say what is bad), anyway, it is quite normal for me to use it, no matter what, please write down the solution first.

Create a shortcut to jvisualvm.exe, right-click the shortcut and select properties, and add "-XX:+PerfBypassFileSystemCheck" in the "Target" column

After the program runs, it will automatically monitor the java program running on the machine (under the Local tab, the java program on the remote server needs to be configured separately). If it is a downloaded jvisualvm, after decompression, run jvisualvm.exe in the bin directory.

 

The first VisualVM under the Local tab is jvisualvm's monitoring of itself, you can see that the resources consumed are still very few, and the second is the native eclipse

The monitoring items are divided into Overview, Monitor, Threads and a Sampler.

1.Overview (jvm startup parameters, system parameters)

You can see the startup parameters of eclipse

(Through these startup parameters, you can determine whether the program has a memory overflow)

 

2.Monitor

Upper left: cpu utilization, gc status monitoring

Upper right: Heap utilization, utilization of permanent memory area

Lower left: Monitoring of classes

Lower right: monitoring of threads

performGC: detailed operating status of gc

HeapDump: the detailed status of the heap (you can see the overview of the heap, all the classes in it, and click into a specific class to view the status of this class)

 

3.Threads

It can display the name and running status of the thread, which is essential when debugging multi-threads, and you can click into a thread to view the detailed running status of this thread

 

Monitor tomcat on the server

The tomcat configuration file catalina.sh adds:

JAVA_OPTS="-Dcom.sun.management.jmxremote.port=9998 
	-Dcom.sun.management.jmxremote.ssl=false 
	-Dcom.sun.management.jmxremote.authenticate=false 
	-Djava.rmi.server.hostname=192.168.58.164"

Parameter Description:

指定了JMX启动的代理端口,这个端口就是visualvm要连接的端口(9998端口不能被别的程序使用netstat -an|gerp 9998)
Dcom.sun.management.jmxremote.port=9998
指定了JMX是否启用ssl
Dcom.sun.management.jmxremote.authenticate=false
指定了JMX是否启用鉴权(需要用户名,密码鉴权)
Dcom.sun.management.jmxremote.authenticate=false
指定了服务器主机名
Djava.rmi.server.hostname=192.168.58.164

Fill in the host name:

Right click to create a jmx connection:

Just fill in the port number:

Configuration is complete:

 

Monitor the java program on the server

Compared to monitoring tomcat, it is a lot more troublesome. You must start the jstatd service in advance (under the ${java_home}/bin directory)

jstatd is an RMI (Remote Method Invocation) server program that monitors the resource occupancy of the JVM from creation to destruction and provides a remote monitoring interface. It is a Daemon program (background process). Ensure that the remote monitoring software is connected to Locally, jstatd must always be running.

To run jstatd, you need to specify the security policy through -J-Djava.security.policy=***, so we need to create a file jstatd.all.policy on the server that specifies the security policy (I put it in the ${java_home}/bin directory Below), the contents of the file are as follows:

grant codebase "file:/home/123/123/jdk1.5.0_15/lib/tools.jar" { 
	permission java.security.AllPermission; 
}; 

Then use this policy file to start the jstatd service

[123@123 bin]$ pwd
/home/123/123/jdk1.5.0_15/bin
[123@123 bin]$ ./jstatd -J-Djava.security.policy=./jstatd.all.policy &

Because the jstatd service needs to be running all the time during the monitoring process, & is added. If you need logs, you can also use:

./jstatd -J-Djava.security.policy=./jstatd.all.policy -J-Djava.rmi.server.logCalls=true

Next, you can configure and monitor the java program running on the server in jvisualvm, which is the same as configuring and monitoring the tomcat server in jvisualvm.

It is important to note that sometimes jvisualvm will report an error when configuring the remote monitoring java program

Click to view error details:

 connection refused to host: 127.0.0.1 preliminary judgment is related to the host name

[123@123 bin]# hostname -i
127.0.0.1
[123@123 bin]# hostname 192.168.58.168

After modifying the jstatd service, restart the jstatd service (many people on the Internet say that the /etc/hosts file of the host should be modified, but I have tested that modifying the /etc/hosts file by myself is ineffective, and the host name must be modified)

Fill in the host name:

 

Here to choose to add a jstatd connection:

 

Simply select the default configuration (port 1099 is used by default):

After clicking ok, all java programs on 168 will be listed automatically:

 

PS:

Plug-ins can also be installed on jvisualvm. The specific steps are tool -> plugin ->aviable plugin. I recommend a very useful plugin VisualGC

After installing this plug-in, a new monitoring item Visual GC will be added, and you can see the usage of each area of ​​the virtual machine memory

    Guess you like

    Origin blog.csdn.net/aiwaston/article/details/104936473