2016-07-08 37 views
0

我有一个使用spring-boot-starter-actuator和io.dropwizard.metrics的Spring引导项目。Jconsole无法连接到本地jmx应用程序

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>io.dropwizard.metrics</groupId> 
     <artifactId>metrics-core</artifactId> 
    </dependency> 

它生成指标,我可以通过url http://myapplication/metrics访问。 我在Wildfly 10独立服务器上部署应用程序。

我想使用jmx来读取jconsole上的指标。 我配置为与JMXReporter发送指标的应用:

@Configuration 
@EnableMetrics 
public class MetricsConfiguration extends MetricsConfigurerAdapter { 
    @Override 
    public void configureReporters(MetricRegistry metricRegistry) { 
     registerReporter(JmxReporter.forRegistry(metricRegistry) 
       .build()) 
       .start(); 
    } 
} 

当我启动服务器和部署应用程序,日志说:

osbaejEndpointMBeanExporter位于托管bean “metricsEndpoint”:与注册JMX服务器的MBean [门户-WS-JMX:类型=端点,名称= metricsEndpoint]

Server logs

当我运行jconsole时,在本地进程列表中,只有JConsole进程和一些灰色PID。如果我选择一个灰色的PID,它会显示“管理代理未启用此过程”。

我也试图使用远程过程连接:

  • 服务:JMX:HTTP的远程处理-JMX://本地主机:9990
  • 服务:JMX:远程+ http://localhost:9990
  • 本地主机:9990

JConsole

但是,这是行不通的。

我试图设置JVM变量:

  • -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only =假

和属性:

  • spring.jmx.enabled =真

它也不起作用。

我能做什么用jconsole读取jmx指标?

回答

1

我发现了一个解决方案在这里:来自Wildfly https://dzone.com/articles/remote-jmx-access-wildfly-or

我的问题。 当我运行JConsole的,我需要的jboss-CLI-client.jar中和的tools.jar到classpath中的JConsole:

$JAVA_HOME/bin/jconsole -J-Djava.class.path=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/jconsole.jar:/opt/wildfly-8.2.0.Final/bin/client/jboss-cli-client.jar 

现在的作品,我可以使用 “服务:JMX:远程+ http://localhost:9990” 连接到JMX。

0

下面是一组命令行参数我用它来生成一个工作的弹簧启动应用程序(虽然使用Tomcat,不Wildfly)通过JConsole的公开的事情:

cmd="$cmd -Dcom.sun.management.jmxremote" 
cmd="$cmd -Dcom.sun.management.jmxremote.port=9899" 
cmd="$cmd -Dcom.sun.management.jmxremote.rmi.port=9811" 
cmd="$cmd -Dcom.sun.management.jmxremote.authenticate=false" 
cmd="$cmd -Dcom.sun.management.jmxremote.ssl=false" 
cmd="${cmd} -Djava.rmi.server.hostname=<IP_OF_YOUR_SERVER>" 

注意的是,应用程序运行上是通过端口9800访问(在我的情况)。但是,端口9811和9899也可以处理JMX(如上所述)。您还需要确保可以通过您可能已设置的任何防火墙访问3个端口。

好运

+0

感谢您的回答。我尝试这个,但它不起作用。 我认为我的问题是由wildyfly引起的。 – YLombardi