restfull api: Health check 規範
healthcheck方法返回版本、日期,便於普羅米修斯等工具監控api\project 的狀態、是否存活、版本是否正確
方案一
一個project添加一個api: healthcheck
Java springboot + maven sample:
1.pom.xml add:
<resources>
<resource>
<directory>src/main/resources.${deploy.type}</directory>
<filtering>true</filtering>
</resource>
</resources>
2.application.yml add:
version: @project.version@
3. class add api method:
@Value("${version}") private String version; @RequestMapping(value = "/healthcheck", method = RequestMethod.GET) public Response<?> healthcheck() { return Response.success(version + System.currentTimeMillis()); }