Spring Actuator 监控管理

Spring Actuator 监控管理

Spring Actuator 是 Spring Boot 提供的一个功能强大的监控和管理端点。它提供了一系列的 HTTP 端点,可以用来监控应用程序的运行状态、健康状况、性能指标等信息。这些端点可以通过 HTTP 或 JMX 访问。

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

Spring Boot Actuator Web API Documentation
常用的端点:

  • /health:用于检查应用程序的健康状况。
    查看详细信息需要新加配置:
    management.endpoint.health.show-details=always
    
  • /info:用于显示应用程序的基本信息。
  • /metrics:用于显示应用程序的性能指标。要再使用/actuator/metrics/{metric.name}分別查看各个指标的详细信息。
  • /trace:用于显示应用程序的请求跟踪信息。
  • /env:用于显示应用程序的环境变量。
  • /beans:用于显示应用程序中所有的 Bean。

例如:

http://localhost:8080/actuator/health

在这里插入图片描述
引入依赖后,SpringBoot 在运行时就會自动开启/actuator/health/actuator/info这两个endpoint。查询暴露的端点:

http://localhost:8080/actuator

但是因为安全因素,所以需要另外设置才能打开這些 endpoint。可在配置里增加配置,控制端口的开闭:

// 开放所有端口
management.endpoints.web.exposure.include=*

// 指定端口开放
management.endpoints.web.exposure.include=beans,mappings

// 指定端口关闭
management.endpoints.web.exposure.exclude=beans
management.endpoints.web.exposure.include=*

// 特殊的,如果要开启/actuator/shutdown,需要额外添加这行
management.endpoint.shutdown.enabled=true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值