IDEA Java性能分析插件VisualVM Launcher 配置(JAVA VisualVM 与Jconsole配置相同)

一、前言

关于 Java VisualVM,想要远程,从网上找了许多资料,发现都不能实现,经过好长时间才摸索出正确连接方式。特此,记录一下,免得重蹈覆辙。下面以连接远程服务器为例。

二、环境

Linux :CentOS7 、tomcat8.5.24、jdk1.8.0_141、

Windows10:jdk1.8.0_141、idea2018.2(ultimate)

三、VisualVM Launcher

1、安装VisualVM Launcher插件

从本地jdk中选择visualvm.exe,进行配置。

idea安装完。

打开JAVA VisualVM

备注:可以从jdk的bin目录下直接执行EXE程序,

 

四、Linux配置

1、配置无需用户密码访问

找到tomcat\bin\catalina.sh文件,进行编辑。

在tomcat的bin目录下的catalina.sh中约308行处(搜索# ----- Execute The Requested Command --------------------------------------)

 

添加如下配置,然后重新启动tomcat即可。(当然不需要用户名密码,就可以访问)

[ $1 != "stop" ] && JAVA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9008 \
-Djava.rmi.server.hostname=192.168.1.111 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false $JAVA_OPTS"
export JAVA_OPTS

添加结果:

  

参数说明:

其中,

-Djava.rmi.server.hostname=10.32.2.24 ---------------- 10.32.2.24为tomcat所在机器的ip地址。
-Dcom.sun.management.jmxremote ----------------- 开启jmx,jdk1.5之前还要手动开启,现在已经默认开启了,可以省略
-Dcom.sun.management.jmxremote.port=1099 -------------------jmx的端口(该端口为未占用端口)
-Dcom.sun.management.jmxremote.authenticate=false ---------------- 不开启用户认证
-Dcom.sun.management.jmxremote.ssl=false ----------------------不开启ssl通信
如果-Dcom.sun.management.jmxremote.authenticate=true,则需要指定jmxremote.password与jmxremote.access
-Dcom.sun.management.jmxremote.password.file=/opt/jdk1.8.0_141_x64/jre/lib/management/jmxremote.password
-Dcom.sun.management.jmxremote.access.file=/opt/jdk1.8.0_141_x64/jre/lib/management/jmxremote.access
Table 2-1 Out-of-the-Box Monitoring and Management Properties
PropertyDescriptionValues

com.sun.management.jmxremote

Enables the JMX remote agent and local monitoring via a JMX connector published on a private interface used by JConsole and any other local JMX clients that use the Attach API. JConsole can use this connector if it is started by the same user as the user that started the agent. No password or access files are checked for requests coming via this connector.

true / false. Default is true.

com.sun.management.jmxremote. port

Enables the JMX remote agent and creates a remote JMX connector to listen through the specified port. By default, the SSL, password, and access file properties are used for this connector. It also enables local monitoring as described for the com.sun.management.jmxremote property.

Port number. No default.

com.sun.management.jmxremote. registry.ssl

Binds the RMI connector stub to an RMI registry protected by SSL.

true / false. Default is false.

com.sun.management.jmxremote. ssl

Enables secure monitoring via SSL. If false, then SSL is not used.

true / false. Default is true.

com.sun.management.jmxremote. ssl.enabled.protocols

A comma-delimited list of SSL/TLS protocol versions to enable. Used in conjunction with com.sun.management.jmxremote.ssl.

Default SSL/TLS protocol version.

com.sun.management.jmxremote. ssl.enabled.cipher.suites

A comma-delimited list of SSL/TLS cipher suites to enable. Used in conjunction with com.sun.management.jmxremote.ssl.

Default SSL/TLS cipher suites.

com.sun.management.jmxremote. ssl.need.client.auth

If this property is true and the property com.sun.management.jmxremote.ssl is also true, then client authentication will be performed.

It is recommended that you set this property to true.

true / false. Default is false.

com.sun.management.jmxremote. authenticate

If this property is false then JMX does not use passwords or access files: all users are allowed all access.

true / false. Default is true.

com.sun.management.jmxremote. password.file

Specifies location for password file. If com.sun.management.jmxremote.authenticate is false, then this property and the password and access files are ignored. Otherwise, the password file must exist and be in the valid format. If the password file is empty or nonexistent, then no access is allowed.

JRE_HOME/lib/management/ jmxremote.password

com.sun.management.jmxremote. access.file

Specifies location for the access file. If com.sun.management.jmxremote.authenticate is false, then this property and the password and access files are ignored. Otherwise, the access file must exist and be in the valid format. If the access file is empty or nonexistent, then no access is allowed.

JRE_HOME/lib/management/ jmxremote.access

com.sun.management.jmxremote.login.config

Specifies the name of a Java Authentication and Authorization Service (JAAS) login configuration entry to use when the JMX agent authenticates users. When using this property to override the default login configuration, the named configuration entry must be in a file that is loaded by JAAS. In addition, the login modules specified in the configuration should use the name and password callbacks to acquire the user's credentials. For more information, see the API documentation forjavax.security.auth.callback.NameCallback and javax.security.auth.callback.PasswordCallback.

Default login configuration is a file-based password authentication.

说明链接:https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html#gdeum

2、配置jmxremote.password与jmxremote.access,开启用户认证。该文件在jdk\jre\lib\management目录下。

复制 jmxremote.password.template 为新的文件jmxremote.password,并且为jmxremote.password与jmxremote.access赋予读写权限。

jmxremote.password模板:

[用户名]       [密码]
mtct          ct.meituan
test          test

jmxremote.access模板:

[用户名]      [权限]
mtct        readwrite
test        readonly

修改完两个模板,保存即可。

五、客户端远程连接(以未开启用户认证为例)

如果开启用户认证,则选中使用安全凭证,并输入用户名,密码。

进入JAVA VisualVM

JConsole连接同理。

还有一种连接方式jstatd连接方式,就不在赘述。

六、期间遇到的问题

1、service:jmx:rmi:///jndi/rmi://10.32.2.24:1099/jmxrmi 连接到 10.32.2.24:1099

多半是Linux服务器没进行对应的配置。

2、如果连接拒绝,检查一下防火墙,是不是防火墙不允许该IP访问。

3、在启动tomcat的时候,日志提示:代理抛出异常错误: java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException:***

首先,检查 当前服务器hostname 是否为 XXX;其次,vim /etc/hosts,检查 ip 地址后面的解析是否为:XXX,没有 更新为XXX

问题发生可能原因:
tomcat 下 bin下 调整了 /catalina.sh ,开启了jmx的配置,其中有一个参数 是关于hostname 的解析 指向了 ip 导致跟tomcat 下 conf/server.xml 下的host 解析域名的冲突。故处理hostname 的解析,执行域名,该问题影响域名指向问题也可以处理掉。

也可以使用hostname 修改一下临时主机名(服务器重启后恢复),即可。

--------------------- 本文来自 maweiba163 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/maweiba163/article/details/51913055?utm_source=copy

 

参考一:https://blog.csdn.net/kingzone_2008/article/details/50865350

  • 12
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
### 回答1: Java VisualVM是一种用于分析Java应用程序的工具,可以使用它来分析dump文件。以下是使用Java VisualVM分析dump文件的步骤: 1. 打开Java VisualVM并选择“File”菜单中的“Load”选项。 2. 选择要分析的dump文件并加载它。 3. 在左侧的“Applications”窗口中选择要分析Java应用程序。 4. 在右侧的“Monitor”窗口中选择要分析的线程或进程,并查看其性能指标和堆栈跟踪信息。 5. 使用Java VisualVM提供的其他工具和插件来进一步分析和优化Java应用程序的性能。 总之,Java VisualVM是一种非常有用的工具,可以帮助开发人员诊断和解决Java应用程序的性能问题。 ### 回答2: Java VisualVM是一个Java虚拟机监视和分析工具。它提供了实时的应用程序性能监控,以及基于某些特定平台的内存和线程分析。使用Java VisualVM可以分析非常详细的诊断信息,它可以非常轻松地获取一个Java应用程序运行时的进程快照,即dump文件。在获取到dump文件后,我们可以通过Java VisualVM对dump文件进行分析,以更深入地了解应用程序的性能状况,从而提高程序的性能。下面我们来具体说明如何使用Java VisualVM分析dump文件。 在使用Java VisualVM分析dump文件之前,首先需要下载和安装Java VisualVMJava VisualVM提供了以下两种方式来分析dump文件: 1.打开本地应用程序 打开Java VisualVM后,从菜单栏中点击File -> Load 即可打开本地应用程序,并可以在Applications选项卡中查看正在运行的Java进程。选取需要分析的进程,然后点击Snapshot按钮,即可生成dump文件。 2.分析远程应用程序 Java VisualVM还提供了通过JMX连接到远程应用程序获取dump文件的方式。选择File -> Add JMX Connection选项,并输入连接的IP地址和端口号。成功连接后,点击Applications选项卡,选择远程应用程序,然后点击Snapshot按钮即可生成dump文件。 在得到dump文件之后,我们可以通过Java VisualVM来进行性能分析。首先我们需要打开dump文件,选择File -> Load Snapshot,选择目标dump文件。在界面的左侧,我们可以看到以下五个选项卡: 1. Overview 用于查看堆内存和线程状况的概览。 2. Monitor 用于实时监控Java应用程序的性能和资源使用情况,如CPU、内存、线程等。 3. Heap Dump 用于查看内存快照中的详细信息,帮助找出内存泄漏和对象占用情况。 4. Threads 用于查看各个线程的状态和历史记录,并对线程进行诊断和采样。 5. Samples 用于对应用程序的性能瓶颈进行采样和分析,查找性能瓶颈和优化应用程序。 通过以上选项卡,我们可以对应用程序进行更加深入的性能分析,找出应用程序的性能瓶颈,帮助我们更好地优化应用程序的性能。 ### 回答3: Java VisualVMJava 官方提供的一个性能分析工具,它可以通过连接远程或本地的 JVM 进程,收集各种性能相关的数据,包括堆内存、CPU、线程、GC 等。同时,Java VisualVM 还能够生成 Heap Dump 文件,用于分析内存泄露等问题。本文主要介绍如何使用 Java VisualVM 分析 Heap Dump 文件。 一、导出 Heap Dump 文件 在 Java VisualVM 中,我们可以在“Applications” 中找到正在运行的 Java 应用程序,右键点击应用程序进程并选择“Heap Dump”即可生成 Heap Dump 文件,存放在本地文件系统中。该文件包含了 JVM 进程的整个内存快照,用于分析内存泄露、对象引用等问题。 二、分析 Heap Dump 文件 1. 打开 Heap Dump 文件 将 Heap Dump 文件导入到 Java VisualVM 中,可以通过“File”-”Load”-”Heap Dump”来打开。 2. 了解 Heap Dump 概要信息 通过查看 Heap Dump 的概要信息,可以了解到该应用程序的总内存使用量、对象个数、堆内存各区域的使用情况等。 3. 查看对象实例 在“Classes”标签页中,我们可以查看 Heap Dump 文件中所有的类,其中包含每个对象的实例数、占用内存大小等信息。可以通过该信息找到占用内存较大的对象,进一步分析其使用情况。 4. 分析对象引用 通过“References”标签页,我们可以查看各个对象之间的引用关系。可以通过该信息找到内存泄露的对象引用,找到引用该对象的对象,或使用MAT等工具分析该对象的引用链路,定位到引用根源。 5. 分析堆内存分布 通过“Heap Dump”标签页,我们可以查看堆内存分布情况。可以查看到堆内存各区域的内存大小及使用情况,从而了解内存的占用情况。 三、结论 本文介绍了如何使用 Java VisualVM 分析 Heap Dump 文件,通过了解对象实例、对象引用、堆内存分布等信息,找到内存泄露的对象,并定位到引用根源,进一步优化应用程序,提高其性能

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值