Java 使用visualvm和JMX进行远程监控
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30069643/
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
Remote monitoring with visualvm and JMX
提问by user152468
I would like to monitor a remotely running java (spring boot) application with jvisualvm (or jconsole). When running locally, I can see the managed beans in both jvisualvm and jconsole. When running remotely I cannot connect. I tried it with several different java processes (e.g. with spring xd). Looking for answers here on SO and on Google did not help.
我想使用 jvisualvm(或 jconsole)监视远程运行的 java(spring boot)应用程序。在本地运行时,我可以在 jvisualvm 和 jconsole 中看到托管 bean。远程运行时,我无法连接。我尝试了几个不同的 java 进程(例如使用 spring xd)。在 SO 和 Google 上寻找答案并没有帮助。
These are my JAVA_OPTS (on the remote host):
这些是我的 JAVA_OPTS(在远程主机上):
$ echo $JAVA_OPTS
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.59.99
Then I simply start the program as follows (this is for spring xd, but I experience the same problem with other java programs).
然后我简单的启动程序如下(这个是针对spring xd的,但是我用其他java程序也遇到了同样的问题)。
$ bin/xd/xd-singlenode
The server process seems to pick up the options:
服务器进程似乎选择了以下选项:
$ ps -ef | grep single
vagrant 22938 19917 99 06:38 pts/2 00:00:03 /usr/lib/jvm/java-8- oracle/jre/bin/java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.59.99 -Dspring.application.name=admin -Dlogging.config=file:/home/vagrant/spring-xd-1.1.0.RELEASE/xd/config///xd-singlenode-logger.properties -Dxd.home=/home/vagrant/spring-xd-1.1.0.RELEASE/xd -Dspring.config.location=file:/home/vagrant/spring-xd-1.1.0.RELEASE/xd/config// -Dxd.config.home=file:/home/vagrant/spring-xd-1.1.0.RELEASE/xd/config// -Dspring.config.name=servers,application -Dxd.module.config.location=file:/home/vagrant/spring-xd-1.1.0.RELEASE/xd/config//modules/ -Dxd.module.config.name=modules -classpath (...)
The java version on the remote host (ubuntu linux vm) is:
远程主机(ubuntu linux vm)上的java版本是:
$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The java version on the local machine (Mac OS) is slightly different:
本地机器(Mac OS)上的java版本略有不同:
$ java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
In jvisualvm I add the remote connection as follows (tried both with ssl connection and without):
在 jvisualvm 中,我按如下方式添加远程连接(尝试使用 ssl 连接和不使用 ssl 连接):
This is the error message jvisualvm gives me:
这是 jvisualvm 给我的错误消息:
I can connect from the local host to the remote host with the command telnet 192.168.59.99:9010
, when the remote process is running -- so this does not seem to be a firewall problem.
telnet 192.168.59.99:9010
当远程进程正在运行时,我可以使用命令从本地主机连接到远程主机——所以这似乎不是防火墙问题。
Any help is highly appreciated.
任何帮助都受到高度赞赏。
采纳答案by Arnab Biswas
Please use the following JVM options :
请使用以下 JVM 选项:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.59.99
In the Jconsole use the following to connect:
在 Jconsole 中,使用以下内容进行连接:
service:jmx:rmi:///jndi/rmi://192.168.59.99:9010/jmxrmi
回答by thangdc94
Arnab Biswas's anwser not work in my case. After an hour of researching, I found out that JMX runs on top of RMI, and as such, there are 2 ports that JMX utilizes:
Arnab Biswas 的 anwser 在我的情况下不起作用。经过一个小时的研究,我发现 JMX 运行在 RMI 之上,因此,JMX 使用了 2 个端口:
- The JMX connect port. (
-Dcom.sun.management.jmxremote.port
) - The (infamously) roaming RMI data port. (
-Dcom.sun.management.jmxremote.rmi.port
)
- JMX 连接端口。(
-Dcom.sun.management.jmxremote.port
) - (臭名昭著的)漫游 RMI 数据端口。(
-Dcom.sun.management.jmxremote.rmi.port
)
RMI data port will open a random port start from 1099
. By setting the port used by the RMI registry and the RMI server to the same port, tunneling will be much easier.
RMI 数据端口将从1099
. 通过将 RMI 注册表和 RMI 服务器使用的端口设置为相同的端口,隧道将变得更加容易。
So I need to add -Dcom.sun.management.jmxremote.rmi.port=9010
to JVM options
所以我需要添加-Dcom.sun.management.jmxremote.rmi.port=9010
到 JVM 选项
And I need to use the following JVM options :
我需要使用以下 JVM 选项:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.59.99
Read more:
阅读更多: