java - 使用 Spring Boot 应用程序的自定义健康指标实现健康检查休息 API
问题描述
我正在开发在8080以外的端口上运行的 Spring Boot Web 应用程序。我需要编写一个 rest API 来检查应用程序以及底层数据库的运行状况。
同样,我浏览过这篇文章:如何在 Spring Boot Health 中添加自定义健康检查?,但没有找到任何具体的实现。
其实我想做以下事情:
所有下游 API 的健康检查
DB是否工作正常
那么有人可以帮我解决这个问题吗?谢谢。
解决方案
Spring boot actuator 可以自动为您创建常见的健康检查(也为您的数据库)和一个 REST API。
要开始添加以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
然后 Spring Boot 将在下面公开一些执行器端点:
/actuator
与您最相关的可能是:
/actuator/health
要向此端点添加自定义运行状况检查,您可以按照链接帖子的答案中提供的指南进行操作。
推荐阅读
- php - 使用带有标题的php强制下载时如何向用户发送消息
- text - Flutter的TextBaseline枚举中的字母和表意之间有什么区别
- python - 如果我向 csv 添加太多要处理的 url,我编写的此代码将失败。怎么提高?
- python - 可以使用 boto3 获取 S3 存储桶使用的带宽吗?
- android - 无法解析 graphql 生成的类上的符号
- crystal-reports - 如何根据组中一个成员的值取消选择整个组?
- vim - 我可以通过键映射将参数传递给函数吗?
- r - 将 JavaScript 生成的数据导入 R 或 Stata
- python - 你能检查两个对象实例是否相同
- php - Opencart - 如何在结帐页面上默认选择“条款”