01使用方法
- 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 配置监控端点
management:
endpoints:
web:
base-path: /management
exposure:
include: '*'
endpoint:
health:
show-details: always
auditevents:
enabled: false
info:
git:
mode: full
health:
mail:
enabled: false
metrics:
enabled: false
server:
servlet:
context-path: /uaa
- 已提供的健康检查端点
Name | Description |
---|---|
CassandraHealthIndicator | 检查是否启动了Cassandra数据库 |
DiskSpaceHealthIndicator | 检查磁盘空间是否不足 |
DataSourceHealthIndicator | 检查是否可以获得到数据源的连接 |
ElasticsearchHealthIndicator | 检查Elasticsearch集群是否已启动 |
InfluxDbHealthIndicator | 检查时序性数据库服务器是否已启动 |
JmsHealthIndicator | 检查JMS代理是否已启动 |
MailHealthIndicator | 检查邮件服务器是否已启动 |
MongoHealthIndicator | 检查Mongo数据库是否已启动 |
Neo4jHealthIndicator | 检查Neo4i服务器是否已启动 |
RabbitHealthIndicator | 检查rabbitmq服务器是否已启动 |
RedisHealthIndicator | 检查Redis服务器是否已启动 |
SolrHealthIndicator | 检查Solr服务器是否已启动 |
可以通过 management.health.defaults.enabled
这个配置项将它们全部禁用掉,
也可以通过management.health.xxxx.enabled
将其中任意一个禁用掉。
- 定义 HealthIndicator 健康检查
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class CcpHealthIndicator implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
}
网友评论