Java VisualVM
Java VisualVM介绍
Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications. Various optional tools, including Java VisualVM, are provided with Sun's distribution of the Java Development Kit (JDK) for retrieving different types of data about running JVM software instances. For example, most of the previously standalone tools JConsole, jstat, jinfo, jstack, and jmap are part of Java VisualVM. Java VisualVM federates these tools to obtain data from the JVM software, then re-organizes and presents the information graphically, to enable you to view different data about multiple Java applications uniformly, whether they are running locally or on remote machines. Furthermore, developers can extend Java VisualVM to add new functionality by creating and posting plug-ins to the tool's built-in update center.
Java VisualVM can be used by Java application developers to troubleshoot applications and to monitor and improve the applications' performance. Java VisualVM can allow developers to generate and analyse heap dumps, track down memory leaks, browse the platform's MBeans and perform operations on those MBeans, perform and monitor garbage collection, and perform lightweight memory and CPU profiling.
Java VisualVM
Java Visual使用
通过JMX监控远程服务器jvm资源使用情况。
JMX:Java Management Extensions ,即 Java 管理扩展 , 是一个为应用程序、设备、系统等植入管理功能的框架。 JMX 可以跨越一系列异构操作系统平台、系统体系结构和 网络传输协议,灵活的开发无缝集成的系统、网络和服务管理应用。
需要在远程服务器启动java程序(比如Tomcat的catalina.sh)时在JAVA_OPTS中指定如下参数(最后一项参数可选):
-Dcom.sun.management.jmxremote.port=8899 ---配置远程 connection 的端口号,确保该端口没有被占用
-Dcom.sun.management.jmxremote.ssl=false ---指定JMX 是否启用 ssl
-Dcom.sun.management.jmxremote.authenticate=false ---指定JMX 是否启用鉴权(需要用户名,密码鉴权)
-Djava.rmi.server.hostname=127.0.0.1 ---配置server 的 IP
Java程序启动项设置(追加java visualVM相关配置项):
java -Dcom.sun.management.jmxremote.port=8899 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
Java VisualVM - Connecting to JMX Agents Explicitly
参考文档:
Memory Profiling using Visual VM
Configuring Java JVM Heap Size