Spring Boot Actuator

Spring Boot Actuator

节选自《Netkiller Spring Cloud 手札》

 

健康检查、审计、统计和监控

Maven 依赖

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

与 Spring Boot Actuator 有关的配置

application.properties

跨域配置

management.endpoints.web.cors.allowed-origins=https://example.com
management.endpoints.web.cors.allowed-methods=GET,POST 

禁用HTTP端点

如果您不想通过HTTP公开端点,则可以将管理端口设置为-1,如以下示例所示:

management.server.port=-1 

actuator 接口

neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator | jq
{
 "_links": {
 "self": {
 "href": "http://localhost:8080/actuator",
 "templated": false
 },
 "health": {
 "href": "http://localhost:8080/actuator/health",
 "templated": false
 },
 "health-component": {
 "href": "http://localhost:8080/actuator/health/{component}",
 "templated": true
 },
 "health-component-instance": {
 "href": "http://localhost:8080/actuator/health/{component}/{instance}",
 "templated": true
 },
 "info": {
 "href": "http://localhost:8080/actuator/info",
 "templated": false
 }
 }
}

健康状态

curl localhost:8080/actuator/health
 
neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator/health | jq
{
 "status": "UP"
}

健康状态

详细的健康状态信息

management.endpoint.health.show-details=always 

neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator/health | jq
{
 "status": "UP",
 "details": {
 "diskSpace": {
 "status": "UP",
 "details": {
 "total": 250790436864,
 "free": 23556112384,
 "threshold": 10485760
 }
 }
 }
}  

关机

配置文件中加入

management.endpoint.shutdown.enabled=true 

curl -X POST localhost:8080/actuator/shutdown 

info 配置信息

返回 application.properties 文件中定义的 info 配置信息,如:

# info端点信息配置

info.app.name=spring-boot-example
info.app.version=v1.0.0 

neo@MacBook-Pro ~ % curl -s http://localhost:8080/actuator/info | jq 
{
 "app": {
 "name": "spring-boot-example",
 "version": "v1.0.0"
 }
}

计划任务

http://localhost:8080/actuator/scheduledtasks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

netkiller-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值