SpringBoot Actuator的使用

在线上工程中,对服务可用性或者是中间件可用性的检测,是十分有必要的,具体实现,可以自己写一个特殊的接口,接口的实现可以自己实现对中间件比如redis,hbase,jms等服务可用性的监测,但springboot有一个十分便捷的工具,能提供服务的监测,就是本次的主题:SpringBoot Actuator

简单地使用,就是引入jar,配置一下application.yml就行了

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

然后配置文件引入一下:

management:
  endpoints:
    web:
      exposure:
        include: "*"
  server:
    port: 10111
    servlet:
      context-path: /
    ssl:
      enabled: false
  endpoint:
    health:
      show-details: always

最终通过postman调用接口:

这是自己按照参考实现的,重要的是自己做个记录

下面给一些基本的参考链接:

简书的Actuator

各个接口的详细使用说明

Spring Boot Actuator是Spring Boot提供的一个管理和监控应用程序的工具集。它提供了一些有用的端点(Endpoints),可以让你查看和管理Spring Boot应用程序的运行状态,如健康状态、内存使用情况、线程信息等等。 下面是Spring Boot Actuator的正确使用方法: 1. 引入依赖 在pom.xml中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ``` 2. 配置端点 在application.properties中配置端点: ``` management.endpoints.web.exposure.include=* ``` 上述配置将所有的端点都暴露出来,如果你只想暴露特定端点,可以使用以下配置: ``` management.endpoints.web.exposure.include=health,info ``` 3. 查看端点 启动应用程序后,可以通过以下URL查看端点: ``` http://localhost:8080/actuator ``` 这将显示所有可用的端点。例如,要查看健康状态,可以使用以下URL: ``` http://localhost:8080/actuator/health ``` 4. 自定义端点 可以通过实现Endpoint接口来自定义端点,例如: ``` @Component public class CustomEndpoint implements Endpoint<Map<String, Object>> { @Override public String getId() { return "custom"; } @Override public boolean isEnabled() { return true; } @Override public boolean isSensitive() { return true; } @Override public Map<String, Object> invoke() { Map<String, Object> result = new HashMap<>(); result.put("message", "Hello, world!"); return result; } } ``` 在应用程序中注入该组件,然后可以通过以下URL访问自定义端点: ``` http://localhost:8080/actuator/custom ``` 以上就是Spring Boot Actuator的正确使用方法,它可以帮助你更好地管理和监控Spring Boot应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值