尝试以编程方式访问jmx指标时出错

时间:2018-09-10 15:18:38

标签: java jmx

我正在尝试测试一个简单的Java应用程序,该应用程序应访问Windows桌面上的本地jmx指标。这是尝试访问远程服务器上的kafka指标的基础,我正在尝试了解基本概念。我希望能帮助您理解这些概念,而不是被否决。

我发现的代码是访问本地jmx的简单jmx客户端脚本。我在春季运行此脚本时遇到错误,解决在搜索中找到此脚本的解决方案似乎表明服务器应该正在运行,但是我不确定这意味着什么。

代码如下:

private static String hostName = "127.0.0.1";
private static int port = 1099;
private static String objectGridName = "library";
private static String mapSetName = "ms1";


public static void main(String[] args) throws Exception{

    String serviceURL = "service:jmx:rmi:///jndi/rmi://" + hostName + 
          ":" + port + "/jmxrmi";
    JMXServiceURL jmxURL = new JMXServiceURL(serviceURL);
    JMXConnector jmxCon = JMXConnectorFactory.connect(jmxURL);


    try{

        MBeanServerConnection catalogServerConnection = 
            jmxCon.getMBeanServerConnection();

在JMXConnectorFactory.connect上,出现以下错误:

Exception in thread "main" java.io.IOException: Failed to retrieve 
RMIServer stub: javax.naming.ServiceUnavailableException [Root exception 
is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; 
  nested exception is: 
java.net.ConnectException: Connection refused: connect]
at javax.management.remote.rmi.RMIConnector.connect(Unknown Source)
at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
at jmxConsumer.jmxMain.main(jmxMain.java:25)
Caused by: javax.naming.ServiceUnavailableException [Root exception is 
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested 
exception is: 
java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(Unknown 
   Source)
at javax.management.remote.rmi.RMIConnector.findRMIServer(Unknown 
   Source)
... 4 more

我同时在后台运行jconsole和jVirtualVM。我还应该做些其他事情来解决这个问题吗?

0 个答案:

没有答案