如何在Spring Boot独立应用程序中激活JMX监控

人气:59 发布:2023-01-03 标签: java spring-boot jmx jolokia

问题描述

我看了几乎所有的文档,但几乎不能抓住这个神秘的东西。 那么我的问题是我可以通过http jmx url使用我的独立的Spring Boot应用程序来监控我的应用程序的运行状况和其他指标吗?我是否需要为此配置其他内容? 我已在启动应用程序中添加了以下依赖项。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jolokia</groupId>
        <artifactId>jolokia-core</artifactId>
    </dependency>

我还在配置文件中配置了以下属性。

management.endpoints.web.exposure.include=*
management.endpoints.jmx.unique-names=true
management.server.port=8080
management.server.ssl.enabled=false

当我尝试点击URL:http://localhost:8080/actuator/jolokia/health时,无法看到任何结果。

还尝试添加如下所示的自定义终结点,但不起作用。

@Endpoint(id="mypoint")
    @Component
    public class myPointEndPoint {
        @ReadOperation
        public String mypoint(){
            return "Hello" ;
        }

具有附加属性 Management.endpoint t.mypoint t.Enabled=True

推荐答案

问题出在您尝试调用的URL。 首先,使用http://localhost:8080/actuator/jolokia/list

检索可能的MBean

查看Health mBean时,必须提供唯一的名称和操作(Op)。

在我的例子中,它看起来像:http://localhost:8080/actuator/jolokia/exec/org.springframework.boot:type=Endpoint,name=Health,identity=4200098/health

同时查看Jolokia文档:https://jolokia.org/reference/html/index.html

16