下面列出了怎么用org.springframework.boot.actuate.health.CompositeHealthIndicator的API类实例代码及写法,或者点击链接到github查看源代码。
@Bean
@Autowired(required = false)
@ConditionalOnMissingBean
public HealthIndicator jikexiuHealthIndicator(RedisQueueImpl redisQueue,
RedisQueueProperties properties) {
CompositeHealthIndicator compositeHealthIndicator = new
CompositeHealthIndicator(healthAggregator);
Map<String, LeaderManager> leaderManagerMap = AppEnvContext.getCtx().getBeansOfType(LeaderManager.class);
LeaderManager manager = null;
if (leaderManagerMap != null && !leaderManagerMap.isEmpty()) {
manager = AppEnvContext.getCtx().getBean(SimpleLeaderManager.class);
}
compositeHealthIndicator.addHealthIndicator("dq", new QueueHealthIndicator(
redisQueue, manager, properties));
return compositeHealthIndicator;
}
@Autowired
public PipelineController(
ExecutionLauncher executionLauncher,
ExecutionRepository executionRepository,
ObjectMapper kayentaObjectMapper,
ConfigurableApplicationContext context,
HealthIndicatorRegistry healthIndicators,
HealthAggregator healthAggregator,
ScheduledAnnotationBeanPostProcessor postProcessor) {
this.executionLauncher = executionLauncher;
this.executionRepository = executionRepository;
this.kayentaObjectMapper = kayentaObjectMapper;
this.context = context;
this.healthIndicator = new CompositeHealthIndicator(healthAggregator, healthIndicators);
this.postProcessor = postProcessor;
}
@Bean
@Autowired(required = false)
@ConditionalOnMissingBean
public HealthIndicator jikexiuHealthIndicator(RedisQueue redisQueue, RedisQueueProperties properties) {
CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
Map<String, LeaderManager> leaderManagerMap = AppEnvContext.getCtx().getBeansOfType(LeaderManager.class);
LeaderManager manager = null;
if (leaderManagerMap != null && !leaderManagerMap.isEmpty()) {
manager = AppEnvContext.getCtx().getBean(SimpleLeaderManager.class);
}
compositeHealthIndicator.addHealthIndicator(Constants.HEALTH_INDICATOR_NAME, new QueueHealthIndicator(redisQueue, manager, properties));
return compositeHealthIndicator;
}
public HealthMetricsConfiguration(HealthAggregator healthAggregator, List<HealthIndicator> healthIndicators,
MeterRegistry registry, PlatformTag platformTag) {
healthIndicator = new CompositeHealthIndicator(healthAggregator);
healthIndicators.forEach(h -> {
registry.gauge("health." + h.getClass().getSimpleName().replace("HealthIndicator", "").toLowerCase(),
platformTag.getTags(), h, HealthMetricsConfiguration::getStatusCode);
healthIndicator.addHealthIndicator(h.toString(), h);
});
registry.gauge("health", platformTag.getTags(), healthIndicator, HealthMetricsConfiguration::getStatusCode);
}
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
for (CrudRepository repository : repositories) {
String name = DbCountRunner.getRepositoryName(repository.getClass());
compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
}
return compositeHealthIndicator;
}
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
for (CrudRepository repository : repositories) {
String name = DbCountRunner.getRepositoryName(repository.getClass());
compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
}
return compositeHealthIndicator;
}
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
for (CrudRepository repository : repositories) {
String name = DbCountRunner.getRepositoryName(repository.getClass());
compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
}
return compositeHealthIndicator;
}
public BootHealthCheckHandler(
ApplicationInfoManager applicationInfoManager,
HealthAggregator aggregator,
Map<String, HealthIndicator> healthIndicators) {
this.applicationInfoManager =
Objects.requireNonNull(applicationInfoManager, "applicationInfoManager");
this.aggregateHealth = new CompositeHealthIndicator(aggregator, healthIndicators);
}