SpringBoot Admin
能够看做是Spring actuator 端点监控的一个UI界面,能够很方便的查看服务的运行状况。react
如上图,在项目整合了部分组件后,出现状态显示不在线,但应用仍是可以正常的对外提供服务。git
Spring actuator health endpoint数据
curl http://127.0.0.1:5002/actuator/health
{"status":"DOWN"}
复制代码
SpringBoot Admin
没法获取更多的细节, 建议开发环境开启端点的详细信息。
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always #dev open
复制代码
sentinel
状态不对影响全局状态为
down
curl http://127.0.0.1:5002/actuator/health
{"status":"DOWN","components":{"discoveryComposite":{"status":"UP","components":{"discoveryClient":{"status":"UP","details":{"services":["pigx-upms-biz","pigx-tx-manager","pigx-daemon-elastic-job","pigx-mp-platform","pigx-daemon-quartz","pigx-gateway","pigx-auth","pigx-pay-platform","pigx-codegen","pigx-oa-platform","pigx-monitor"]}}}},"diskSpace":{"status":"UP","details":{"total":42927636480,"free":21334122496,"threshold":10485760}},"nacosConfig":{"status":"UP"},"nacosDiscovery":{"status":"UP"},"ping":{"status":"UP"},"reactiveDiscoveryClients":{"status":"UP","components":{"Simple Reactive Discovery Client":{"status":"UP","details":{"services":[]}}}},"redis":{"status":"UP","details":{"version":"5.0.7"}},"refreshScope":{"status":"UP"},"sentinel":{"status":"DOWN","details":{"dataSource":{},"enabled":true,"dashboard":{"description":"pigx-sentinel:5020 can't be connected","status":"DOWN"}}}}}
复制代码
protected void doHealthCheck(Health.Builder builder) throws Exception {
Map<String, Object> detailMap = new HashMap<>();
// 获取心跳发送器
HeartbeatSender heartbeatSender = HeartbeatSenderProvider
.getHeartbeatSender();
// 发送心跳
boolean result = heartbeatSender.sendHeartbeat();
if (result) {
// 成功标记为UP
detailMap.put("dashboard", Status.UP);
}
else {
// 失败 标记为down
dashboardUp = false;
detailMap.put("dashboard", new Status(Status.DOWN.getCode(),
consoleServer + " can't be connected"));
}
}
// If Dashboard and DataSource are both OK, the health status is UP
if (dashboardUp && dataSourceUp) {
builder.up().withDetails(detailMap);
}
else {
builder.down().withDetails(detailMap);
}
}
复制代码
public boolean sendHeartbeat() throws Exception {
// 1. 判断客户端是和服务端是否交互 ,只有交互时dashboard 才有数据展现
if (TransportConfig.getRuntimePort() <= 0) {
RecordLog.info("[SimpleHttpHeartbeatSender] Runtime port not initialized, won't send heartbeat");
return false;
}
InetSocketAddress addr = getAvailableAddress();
if (addr == null) {
return false;
}
// 2. 访问dashboard 的接口
SimpleHttpRequest request = new SimpleHttpRequest(addr, TransportConfig.getHeartbeatApiPath());
request.setParams(heartBeat.generateCurrentMessage());
SimpleHttpResponse response = httpClient.post(request);
if (response.getStatusCode() == OK_STATUS) {
return true;
}
return false;
}
复制代码
查看 sentinel client
的日志github
cat ~/csp/sentinel-record.log
2020-03-23 13:54:04.634 INFO [SimpleHttpHeartbeatSender] Runtime port not initialized, won't send heartbeat
复制代码
开始是第一步没有初始化交互形成,服务判断为 down
web
commandCenter.start()
public class CommandCenterInitFunc implements InitFunc {
@Override
public void init() throws Exception {
CommandCenter commandCenter = CommandCenterProvider.getCommandCenter();
if (commandCenter == null) {
RecordLog.warn("[CommandCenterInitFunc] Cannot resolve CommandCenter");
return;
}
commandCenter.beforeStart();
// 开始初始化端口交互
commandCenter.start();
RecordLog.info("[CommandCenterInit] Starting command center: "
+ commandCenter.getClass().getCanonicalName());
}
}
复制代码
public class SentinelAutoConfiguration {
@Value("${project.name:${spring.application.name:}}")
private String projectName;
@Autowired
private SentinelProperties properties;
@PostConstruct
private void init() {
// earlier initialize
if (properties.isEager()) {
InitExecutor.doInit();
}
}
复制代码
spring:『★★★★★』 基于Spring Boot 2.二、 Spring Cloud Hoxton & Alibaba、 OAuth2 的RBAC 权限管理系统
application:
name: @artifactId@
cloud:
sentinel:
eager: true
复制代码