| management: |
| health: |
| enabled: true |
| show-details: always |
| @Component |
| public class MyComHealthIndicator extends AbstractHealthIndicator { |
| |
| |
| |
| |
| |
| |
| @Override |
| protected void doHealthCheck(Health.Builder builder) throws Exception { |
| |
| Map<String,Object> map = new HashMap<>(); |
| |
| if(1 == 2){ |
| |
| builder.status(Status.UP); |
| map.put("count",1); |
| map.put("ms",100); |
| }else { |
| |
| builder.status(Status.OUT_OF_SERVICE); |
| map.put("err","连接超时"); |
| map.put("ms",3000); |
| } |
| builder.withDetail("code",100) |
| .withDetails(map); |
| } |
| |
| } |
| # 方式1:在yml中配置 |
| info: |
| appName: boot-admin |
| version: 2.0.1 |
| mavenProjectName: @project.artifactId@ #使用@@可以获取maven的pom文件值 |
| mavenProjectVersion: @project.version@ |
| |
| # 方式2:编写InfoContributor |
| import java.util.Collections; |
| import org.springframework.boot.actuate.info.Info; |
| import org.springframework.boot.actuate.info.InfoContributor; |
| import org.springframework.stereotype.Component; |
| |
| @Component |
| public class ExampleInfoContributor implements InfoContributor { |
| |
| @Override |
| public void contribute(Info.Builder builder) { |
| builder.withDetail("example", |
| Collections.singletonMap("key", "value")); |
| } |
| |
| } |
| |
| # 使用http方式查看,yml配置和实现类方式的内容都会显示 |
| http: |
| # 方式1 |
| @Service |
| public class CityServiceImpl implements CityService { |
| |
| @Autowired |
| CityMapper cityMapper; |
| |
| |
| Counter counter; |
| |
| |
| public CityServiceImpl(MeterRegistry meterRegistry){ |
| counter = meterRegistry.counter("cityService.saveCity.count"); |
| } |
| |
| public City getById(Long id){ |
| return cityMapper.getById(id); |
| } |
| |
| |
| public void saveCity(City city) { |
| counter.increment(); |
| cityMapper.insert(city); |
| } |
| |
| } |
| |
| # 方式2 |
| @Bean |
| MeterBinder queueSize(Queue queue) { |
| return (registry) -> Gauge.builder("queueSize", queue::size).register(registry); |
| } |
| @Component |
| @Endpoint(id = "container") |
| public class DockerEndpoint { |
| |
| |
| @ReadOperation |
| public Map getDockerInfo(){ |
| return Collections.singletonMap("info","docker started..."); |
| } |
| |
| @WriteOperation |
| private void restartDocker(){ |
| System.out.println("docker restarted...."); |
| } |
| |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?