Using visual VM to remotely monitor the server status (graphical interface)

Posted by jcornett on Wed, 09 Mar 2022 06:44:17 +0100

Using visual VM to remotely monitor the server status (graphical interface)

Purpose:

  1. View the current tomcatcup, number of threads, and heap usage

  1. All threads can be viewed in the background if the current thread card is referenced

  1. View current GC status

  1. The stack and heap can be sampled to check memory overflow and other problems

Heap snapshot:

  1. Server execute command

    jmap -dump:format=b,file = snapshot storage path process ID

    You can also add the parameter "dumpmemory: + dumpooxx" to the parameter "snapshot out"

  1. Load snapshot

  1. Download the snapshot locally, select the snapshot and open it

  1. You can view the current heap and check whether the memory is not released

  1. Online case:

https://segmentfault.com/a/1190000021442637

https://blog.csdn.net/chwshuang/article/details/44202491

to configure:

  1. Modify the startup.of tomcat SH file

export CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote ##Enable JMX
-Djava.rmi.server.hostname=192.168.99.125  ##Host name, just fill in the server IP
-Dcom.sun.management.jmxremote.port=7001  ##jmx listening port
-Dcom.sun.management.jmxremote.ssl=false	##Whether to use ssl
-Dcom.sun.management.jmxremote.authenticate=true	##Enable authentication
-Dcom.sun.management.jmxremote.password.file=/usr/local/jdk1.8.0_181/jre/lib/management/jmxremote.password	##User name and password files
-Dcom.sun.management.jmxremote.access.file=/usr/local/jdk1.8.0_181/jre/lib/management/jmxremote.access	##User access file
"
  1. Modify jmxremote Access, add user name and permission at the bottom of the file

​ admin readwrite

  1. Modify jmxremote Password, add user password

​ admin njmind123

  1. Set permissions for profile

​ chmod 600 jmxremote.password jmxremote.access

  1. Configure security policy

File path $JAVA_HOME/jre/lib/security/java.policy is at the end of the file}; Add before

​ permission java.security.AllPermission;

  1. Start jstatd. Note: it is when the monitored machine starts
cd $JAVA_HOME/bin
./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=192.168.99.125 -p 6301  &

## After startup, the registration port 1099 and a random connection port will be opened. The registration port can also be specified through the - P parameter, such as/ jstatd -J-Djava. security. policy=all. policy -p 10003 &

##-J-Djava. security. policy=jstatd. all. The absolute path of the file is followed by the policy = sign;
##-J-Djava.rmi.server.logCalls=true open the log. If the client has a connection request, it can be monitored for troubleshooting;
##-J-Djava.rmi.server.hostname=192.168.134.128 indicates the local address corresponding to the local hostname to ensure that the address can be accessed by the client. Because the ip corresponding to the hostname of some servers is not necessarily connected to the Internet, it is best to specify it directly here;
##-p 3333 specifies the port number of the service. The default is 1099. It is also an optional parameter.

  1. Set up a firewall and open the configured port

    In addition to adding 1099 to the firewall rule, you also need to find another random port and add it to the rule

  2. Add remote host with visual VM (jdk's own program, in the bin directory of jdk)

Add remote. The IP address is the server IP and the port is the port number when jstatd is started

  1. When opening after adding, you need to enter the configured user name and password

It can be monitored through jstatd mode (this mode cannot monitor cpu and class loading)

  1. Right click to add JMX connection and fill in the connection information. The IP address filled in the connection is the server's IP address, startup SH, and enter the user name and password

  1. After adding, you can view it through JMX mode

  1. Visualvm can actively add plug-ins. If you need to modify the plug-in center, you can baidu by yourself or refer to:

https://visualvm.github.io/archive/uc/8u20/updates.xml.gz

  1. Visualvm can actively add plug-ins. If you need to modify the plug-in center, you can baidu by yourself or refer to:

[external chain picture transferring... (img-2zX6taHO-1646803894459)]

https://visualvm.github.io/archive/uc/8u20/updates.xml.gz

Topics: Java Linux server