java 如何使用 VisualVM 和 JMX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30104142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:29:10  来源:igfitidea点击:

How to use VisualVM and JMX?

javarmijmxvisualvmjvisualvm

提问by PedroD

I have tried every recipe in the book, but things just wont work today...

我已经尝试了书中的每一个食谱,但今天就不行了……

I am trying to use VisualVM to profile my Java app running in a remote server, so I googled and googled and googled for ways to do this and I end up with this solution:

我正在尝试使用 VisualVM 来分析我在远程服务器上运行的 Java 应用程序,因此我在 google 上搜索、搜索和搜索以寻找执行此操作的方法,最终得到了以下解决方案:

java -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=9199 \
  -Dcom.sun.management.jmxremote.local.only=false \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.ssl=false \
  -jar bin/felix.jar

Running this will get me JMX to run I guess, so I can see him running on 9199:

我猜运行它会让我运行 JMX,所以我可以看到他在 9199 上运行:

java      21947        root    9u  IPv6 1811434      0t0  TCP *:7192 (LISTEN)
java      26376        root   14u  IPv6 1844518      0t0  TCP *:9199 (LISTEN)

Moreover, I can test that the port is visible on the web:

此外,我可以测试该端口在网络上是否可见:

enter image description here

在此处输入图片说明

Now, when I try to open the connection in VisualVM in my machine (which can also ping the jmx server) this happens:

现在,当我尝试在我的机器上的 VisualVM 中打开连接(它也可以 ping jmx 服务器)时,会发生这种情况:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

I must be so dumb, that everyone in this world was able to put this thing running but me. Damn...

我一定是太笨了,这个世界上的每个人都能够运行这件事,但我除外。该死...

EDIT:I installed wireshark to know what's going on under the hood, so I saw this. As soon as I add a remote IP in VisualVM wireshark starts detecting this repetitive activity:

编辑:我安装了wireshark以了解引擎盖下发生了什么,所以我看到了这个。我在 VisualVM 中添加远程 IP 后,wireshark 开始检测此重复活动:

enter image description here

在此处输入图片说明

However, if I try to add a new JMX connection and ask him to connect, wireshark will not grab even one single packet of that connection attempt.

但是,如果我尝试添加一个新的 JMX 连接并要求他进行连接,wireshark 甚至不会抓取该连接尝试的一个数据包。

enter image description here

在此处输入图片说明

This seems to me that VisualVM is not even trying to connect, despite giving the error message "Cannot connect"...!! What the hell is going on?

在我看来,VisualVM 甚至没有尝试连接,尽管给出了错误消息“无法连接”......!这到底是怎么回事?

采纳答案by prashant thakre

Follow the below steps.
1) Go to remote machine open X11 forwarding,
2) Installed XMING in windows
3) Start visual VM in Remote machine the GUI will come in your windows xming.
4) Instead of IP use localhost and use same port number.

请按照以下步骤操作。
1) 转到远程机器打开 X11 转发,
2) 在 windows 中安装 XMING
3) 在远程机器中启动可视化 VM,GUI 将出现在你的 windows xming 中。
4)代替IP使用本地主机并使用相同的端口号。

If above steps not working it means something is wrong with configuration.
If above steps working fine then go to iptables and ensure port 9199 open for outer world. as well start the program with java -Djava.rmi.server.hostname=YOUR_IP

如果上述步骤不起作用,则意味着配置有问题。
如果上述步骤工作正常,则转到 iptables 并确保端口 9199 对外开放。以及启动程序java -Djava.rmi.server.hostname=YOUR_IP

For more details refer this link

有关更多详细信息,请参阅此链接

回答by Uwe Meding

Start your service using these options:

使用以下选项启动您的服务:

-Djava.rmi.server.hostname=193.163.XXX.XXX
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9199 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

Then you can use jvisualvm or jconsole with just the "193.163.XXX.XXX:9199" address.

然后您可以使用 jvisualvm 或 jconsole 只使用“193.163.XXX.XXX:9199”地址。

回答by Arnab Biswas

Please use the following JVM options :

请使用以下 JVM 选项:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<IP>

In the VisualVM use the following to connect:

在 VisualVM 中,使用以下命令进行连接:

service:jmx:rmi:///jndi/rmi:/<IP>:<PORT>/jmxrmi

Hopefully this will help.

希望这会有所帮助。