通过 JMX 进行监控和管理
Java 管理扩展 (JMX) 提供了一种用于监视和管理应用程序的标准机制。
默认情况下,此功能未启用。
您可以通过设置spring.jmx.enabledconfiguration 属性设置为true.
Spring Boot 公开了最合适的MBeanServer作为 ID 为mbeanServer.
任何使用 Spring JMX 注释 (@org.springframework.jmx.export.annotation.ManagedResource,@ManagedAttribute或@ManagedOperation) 会接触到它。
如果您的平台提供标准的MBeanServer,Spring Boot 会使用该 VMMBeanServer,如有必要。
如果所有这些都失败了,一个新的MBeanServer已创建。
请参阅JmxAutoConfiguration类了解更多详情。
默认情况下, Spring Boot 还会将管理端点作为 JMX MBean 公开在org.springframework.boot域。
要完全控制 JMX 域中的终端节点注册,请考虑注册您自己的EndpointObjectNameFactory实现。
自定义 MBean 名称
MBean 的名称通常是从id的终端节点。
例如,healthendpoint 公开为org.springframework.boot:type=Endpoint,name=Health.
如果您的应用程序包含多个 SpringApplicationContext,您可能会发现名称冲突。
要解决此问题,您可以设置spring.jmx.unique-namesproperty 设置为true,以便 MBean 名称始终是唯一的。
您还可以自定义在其下公开终端节点的 JMX 域。
以下设置显示了在application.properties:
-
Properties
-
YAML
spring.jmx.unique-names=true
management.endpoints.jmx.domain=com.example.myapp
spring:
jmx:
unique-names: true
management:
endpoints:
jmx:
domain: "com.example.myapp"
禁用 JMX 端点
如果您不想通过 JMX 公开端点,则可以设置management.endpoints.jmx.exposure.exclude属性设置为 ,如下例所示:*
-
Properties
-
YAML
management.endpoints.jmx.exposure.exclude=*
management:
endpoints:
jmx:
exposure:
exclude: "*"