SpringBoot监控自定义health信息

目录

1 health显示内部工作组件的状态

2 自定义health信息


1 health显示内部工作组件的状态
 

添加redis坐标后,health里就会显示redis组件的状态

 

2 自定义health信息

 health一般放重要组件的运行信息

package com.qing;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class HealthConfig extends AbstractHealthIndicator {
    //health一般放重要组件的运行信息
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        boolean confition =  true;
        if(confition){
           // builder.up();
            builder.status(Status.UP);
            HashMap map = new HashMap<>();
            map.put("say","hello");
            map.put("say2","goodbye");
            builder.withDetail("say3","happyiness");
            builder.withDetails(map).withDetail("say4","OK");

        }else{
            builder.status(Status.DOWN);
//            Status.UP:成功
//            Status.DOWN:失败
//            Status.OUT_OF_SERVICE:不在服务的
        }

    }
}

猜你喜欢

转载自blog.csdn.net/m0_45877477/article/details/125637353