In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Parsing JVM memory monitoring process example analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
You are familiar with JVM memory monitoring, here is a brief description, here is a detailed configuration process of personal testing, not reproduced and does not need to modify / etc/hosts file under linux, in fact, JDK itself has provided a lot of tools, all in the JAVA_HOME/bin/ directory: jvisualvm, jconsole, jstatd, jmap and so on.
JVM memory monitoring process
This article is a detailed configuration process tested in person. It is not reproduced and the / etc/hosts file does not need to be modified under linux. Due to the needs of the project under construction, monitor the memory usage of tomcat and check for memory leaks. In fact, JDK itself has provided a lot of tools, all of which are in the JAVA_HOME/bin/ directory: jvisualvm, jconsole, jstatd, jmap, and so on. The following is the configuration of the experimental environment:
Client:vista 、 jdk1.6.0_18
Server:linux 、 jdk1.6.0_02 、 tomcat6 、 IP:192.168.8.7
The JVM memory monitoring process is described from the following three aspects:
◆ jmap (MemoryMap) JVM memory object Printing tool
◆ jstatd configuration
◆ Tomcat configuration JMX
First, use jmap to obtain data and view JVM memory monitoring
JAVA_HOME/bin/jmap-histoPID
JAVA_HOME/bin/jmap-histoPID > hismem.txt
The display information includes the Java class, the number of class instance objects, the amount occupied in memory, and the full package name of the class.
/ / dump the information of JVM memory heap into a binary file, which can be used by jstat and EclipseMAT memory analysis tools.
JAVA_HOME/bin/jmap-dump:format=b,file=heap.binPID
Analysis tool of EclipseMAT: http://www.eclipse.org/mat/
Two: jstatd configuration
You need to start the RMI service through jstatd on the server monitored by JVM memory.
Create a new file jstatd.all.policy file with the following contents:
Java code
Grantcodebase "file:$ {java.home} /.. / lib/tools.jar" {permissionjava.security.AllPermission;}
The startup command is as follows:
Java code
/ / the default port is 1099 jstatdjstatd-J-Djava.security.policy=jstatd.all.policy / / specify hostname. Generally speaking, you need to reassign hostname. Otherwise, the connection is not successful jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd.all.policy / / specify hostname designated port jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd.all.policy-p8888 / / start JMX jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd. All.policy- J-Dcom.sun.management.jmxremote.port=8888-J-Dcom.sun.management.jmxremote.ssl=false-J-Dcom.sun.management.jmxremote.authenticate=false / / launch nohupjstatd-J-Djava.rmi.server.hostname=192.168.8.7 in the background-JmurDjava.security.policyaccountebank jstatd.all.policyp8888 & / / the default port is 1099 jstatdjstatd-J-Djava.security.policy=jstatd.all.policy / / specify hostname generally you need to reassign hostname Otherwise, the connection is not successful jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd.all.policy / / specify hostname designated port jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd.all.policy-p8888 / / start JMX jstatd-J-Djava.rmi.server.hostname=192.168.8.7-J-Djava.security.policy=test/jstatd. All.policy- J-Dcom.sun.management.jmxremote.port=8888-J-Dcom.sun.management.jmxremote.ssl=false-J-Dcom.sun.management.jmxremote.authenticate=false / / the background launches nohupjstatd-J-Djava.rmi.server.hostname=192.168.8.7-JMurDjava.security.policymakers testbank jstatd.all.policymurp8888 &
Startup pass: netstat-an | grep8888 can check whether the port has been monitored, and use JAVA_HOME/bin/jmap to view the java process:
Java code
/ / check the situation of this machine jps / / View the situation of the remote computer 192.168.8.7 (default port 1099) jps192.168.8.7 / / view the remote computer 192.168.8.78888 port jpsrmi://192.168.8.7:8888
Open the jvisualvm interface as follows:
Right-click remote and select add remote host:
If the jstatd port is reassigned, select the advanced settings to modify the port, as shown below:
If JMX is also configured, you can add a JMX connection as shown below:
After being added, as shown in the figure:
Third, Tomcat configures JMX to realize JVM memory monitoring
Use hostname-i to check whether it is 127.0.0.1, this step is very important, otherwise the connection will fail, if so, you must configure-Djava.rmi.server.hostname, such as my configuration is-Djava.rmi.server.hostname=192.168.8.7, without modifying the hosts file, modifying this file may also affect other programs.
You just need to find catalina.sh in TOMCAT_HOME/bin/, add the following parameters, and restart tomcat:
Xml code
JAVA_OPTS= "$JAVA_OPTS-Djava.rmi.server.hostname=192.168.8.7-Dcom.sun.management.jmxremote.port=8088-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS= "$JAVA_OPTS-Djava.rmi.server.hostname=192.168.8.7-Dcom.sun.management.jmxremote.port=8088-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=false"
Open the jvisualvm or jconsole tools under JAVA_HOME/bin/ to connect directly, as shown in the following diagram of visualvm connection:
You can also write a Java class TestJMXClient.java to test whether the JMX connection is successful:
Java code
Importjava.util.HashMap; importjava.util.Map; importjavax.management.MBeanServerConnection; importjavax.management.remote.JMXConnector; importjavax.management.remote.JMXConnectorFactory; importjavax.management.remote.JMXServiceURL; / * * @ authorMichael * / publicclassTestJMXClient {/ * * @ paramargs * / publicstaticvoidmain (String [] args) {try {StringjndiPath= "jmxrmi"; Stringserverhost= "192.168.8.7"; Stringserverport= "8088" / / url=service:jmx:rmi:///jndi/rmi://192.168.8.7:8088/jmxrmi Stringjmxurl= "service:jmx:rmi:///jndi/rmi://" + serverhost+ ":" + serverport+ "/" + jndiPath; System.out.println ("jmxurl:" + jmxurl); JMXServiceURLurl=newJMXServiceURL (jmxurl); MapenviMap=newHashMap (); JMXConnectorconnector=JMXConnectorFactory.connect (url,enviMap); MBeanServerConnectionmbsc=connector.getMBeanServerConnection (); System.out.println ("successfulconnected"); connector.close (); System.out.println ("closeconnect") } catch (Exceptione) {System.out.println ("error"); e.printStackTrace ();} is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.