spring boot actuator端点研究

info:

health端点实现:

  1. 获取所有的健康检查结果Health放到map里
@Override
public Health health() {
    Map<String, Health> healths = new LinkedHashMap<String, Health>();
    for (Map.Entry<String, HealthIndicator> entry : this.indicators.entrySet()) {
        healths.put(entry.getKey(), entry.getValue().health());
    }
    return this.healthAggregator.aggregate(healths);
}
  1. 合并Health里的status状态,最后拿列表第一个build返回
@Override
public final Health aggregate(Map<String, Health> healths) {
    List<Status> statusCandidates = new ArrayList<Status>();
    for (Map.Entry<String, Health> entry : healths.entrySet()) {
        statusCandidates.add(entry.getValue().getStatus());
    }
    Status status = aggregateStatus(statusCandidates);
    Map<String, Object> details = aggregateDetails(healths);
    return new Health.Builder(status, details).build();
}
  1. 对Status进行排序归并,获得最终值

就是将所有status按照{“DOWN”,”OUT_OF_SERVICE”,”UP”,”UNKNOWN”}从优先级进行排序,最后取第一个:
- 如果有检测down了则总体是down
- 如果没有down,有检测out_of_service了则总体是out_of_service
- 如果检测只有up或者unknown则总体是up
- 如果全部检测是unknown了则总体是unknown

@Override
protected Status aggregateStatus(List<Status> candidates) {
    // Only sort those status instances that we know about
    List<Status> filteredCandidates = new ArrayList<Status>();
    for (Status candidate : candidates) {
        if (this.statusOrder.contains(candidate.getCode())) {
            filteredCandidates.add(candidate);
        }
    }
    // If no status is given return UNKNOWN
    if (filteredCandidates.isEmpty()) {
        return Status.UNKNOWN;
    }
    // Sort given Status instances by configured order
    Collections.sort(filteredCandidates, new StatusComparator(this.statusOrder));
    return filteredCandidates.get(0);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值