java visualvm 可以通过 JMX 自动连接到远程进程吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3892084/
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-10-30 03:52:18  来源:igfitidea点击:

Can visualvm connect automatically via JMX to a remote process?

javajmxvisualvmjvisualvm

提问by Joe Kearney

I have a Java process running on a remote machine, and the process sets up some mbeans. I also have jstatdrunning on that machine as the same user as the Java process. (The mbeans can be set up programmatically or using -Dcom.sun.management.jmxremote...etc, this doesn't appear to make a difference).

我有一个在远程机器上运行的 Java 进程,该进程设置了一些 mbean。我还jstatd以与 Java 进程相同的用户身份在该机器上运行。(可以以编程方式或使用-Dcom.sun.management.jmxremote...等方式设置 mbean ,这似乎没有区别)。

VisualVM is able to make a jstatdconnection to the process, which it discovers automatically, but this means I don't get access to mbeans or, for example, the CPU history chart. Alternatively I can create an explicit JMX connection, which gives me the usual range of useful tools, but I want for the application to be assigned a random JMX port when it starts, this config can't be static.

VisualVM 能够与jstatd它自动发现的进程建立连接,但这意味着我无法访问 mbeans 或例如 CPU 历史图表。或者,我可以创建一个显式 JMX 连接,这为我提供了常用的有用工具范围,但我希望应用程序在启动时分配一个随机 JMX 端口,此配置不能是静态的。

Is there any way to get VisualVM to auto-connect to my process via JMX? This would require it to auto-discover the JMX ports, but I would have thought jstatdcould do that. Does anyone know of any plugins for visualvm to automate this?

有什么方法可以让 VisualVM 通过 JMX 自动连接到我的进程?这将需要它自动发现 JMX 端口,但我原以为jstatd可以做到这一点。有谁知道visualvm的任何插件来自动化这个?

回答by Tomas Hurka

Unfortunately there is no way to assign random JMX port to the remote application. You can start your remote application with

不幸的是,无法将随机 JMX 端口分配给远程应用程序。您可以使用以下命令启动远程应用程序

-Dcom.sun.management.jmxremote.port=<fixed port>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

and VisualVM will be able to read this configuration via Jvmstat(provide by jstatd) and open JMX connection to your remote application automatically. So you need to assign fixed port(s) to your remote application(s). Once you have it, everything will work fine and VisualVM will automatically connect to your application via JMX (in fact it will combine data from both Jvmstatand JMX).

VisualVM 将能够通过Jvmstat(由 jstatd 提供)读取此配置并自动打开与远程应用程序的 JMX 连接。因此,您需要为远程应用程序分配固定端口。一旦你有了它,一切都会正常工作,VisualVM 将通过 JMX 自动连接到你的应用程序(实际上它将结合来自Jvmstat和 JMX 的数据)。