0

我有一个 Spring Boot 项目,我在其中使用 spring-boot-starter-actuator 和 io.dropwizard.metrics。

    <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 [portal-ws-jmx:type=Endpoint,name=metricsEndpoint]

服务器日志

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

我还尝试使用远程进程连接:

  • 服务:jmx:http-remoting-jmx://localhost:9990
  • 服务:jmx:remote+ http://localhost:9990
  • 本地主机:9990

控制台

但这不起作用。

我试图设置 jvm 变量:

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

和财产:

  • spring.jmx.enabled=true

它也不起作用。

我可以用 jconsole 读取 jmx 指标吗?

4

2 回答 2

1

下面是一组命令行参数,我用来生成一个通过 JConsole 公开内容的工作 spring-boot 应用程序(尽管使用的是 Tomcat,而不是 Wildfly):

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 个端口可以通过您可能设置的任何防火墙访问。

祝你好运

于 2016-07-08T13:45:41.433 回答
1

我在这里找到了解决方案: https ://dzone.com/articles/remote-jmx-access-wildfly-or

我的问题来自 Wildfly。当我运行 jconsole 时,我需要 jboss-cli-client.jar 和 tools.jar 到 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

现在它可以工作了,我可以使用“service:jmx:remote+ http://localhost:9990 ”连接到 jmx。

于 2016-07-11T13:16:27.137 回答