Java Code Examples for org.springframework.boot.actuate.health.Health#Builder
The following examples show how to use
org.springframework.boot.actuate.health.Health#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NacosConfigHealthIndicator.java From nacos-spring-boot-project with Apache License 2.0 | 7 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { builder.up(); NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory .getSingleton(); for (ConfigService configService : nacosServiceFactory.getConfigServices()) { if (configService instanceof NacosServiceMetaData) { NacosServiceMetaData nacosServiceMetaData = (NacosServiceMetaData) configService; Properties properties = nacosServiceMetaData.getProperties(); builder.withDetail( JSON.toJSONString( PropertiesUtils.extractSafeProperties(properties)), configService.getServerStatus()); } if (!configService.getServerStatus().toLowerCase().equals(UP_STATUS)) { builder.down(); } } }
Example 2
Source File: VaultNamespaceTests.java From spring-cloud-vault with Apache License 2.0 | 7 votes |
@Test public void shouldReportReactiveHealth() { ReactiveVaultTemplate reactiveMarketing = new ReactiveVaultTemplate( this.marketingWebClientBuilder, () -> Mono.just(VaultToken.of(this.marketingToken))); Health.Builder builder = Health.unknown(); new VaultReactiveHealthIndicator(reactiveMarketing).doHealthCheck(builder) .as(StepVerifier::create) .assertNext(actual -> assertThat(actual.getStatus()).isEqualTo(Status.UP)) .verifyComplete(); }
Example 3
Source File: ItemDAOHealthIndicator.java From front50 with Apache License 2.0 | 6 votes |
public void run() { Health.Builder healthBuilder = new Health.Builder().up(); try { if (itemDAO.isHealthy()) { healthBuilder.withDetail(itemDAO.getClass().getSimpleName(), "Healthy"); } else { healthBuilder.down().withDetail(itemDAO.getClass().getSimpleName(), "Unhealthy"); } } catch (RuntimeException e) { log.error("ItemDAO {} health check failed", itemDAO.getClass().getSimpleName(), e); healthBuilder .down() .withDetail( itemDAO.getClass().getSimpleName(), format("Unhealthy: `%s`", e.getMessage())); } lastHealth.set(healthBuilder.build()); }
Example 4
Source File: QueueHealthIndicator.java From sdmq with Apache License 2.0 | 6 votes |
@Override public Health health() { try { Health.Builder builder = Health.up(); if (leaderManager == null) { builder.withDetail("run", queue.isRunning()); } else { builder.withDetail("run", queue.isRunning()).withDetail("isMaster", leaderManager.isLeader()); } return builder .withDetail("isCluster", redisQueueProperties.isCluster()) .withDetail("bucketSize", redisQueueProperties.getBucketSize()) .withDetail("prefix", redisQueueProperties.getPrefix()) .withDetail("namespace", ServerNode.NAMESPACE) .build(); } catch (Exception e) { return Health.down(e).build(); } }
Example 5
Source File: GeodeRegionsHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
private BiConsumer<Region<?, ?>, Health.Builder> withRegionStatisticsDetails() { return (region, builder) -> { String regionName = region.getName(); Optional.of(region) .filter(this::isNotLocalDataSet) .filter(this::isStatisticsEnabled) .map(RegionStatisticsResolver::resolve) .ifPresent(cacheStatistics -> builder .withDetail(cacheRegionStatisticsKey(regionName, "cache-statistics-type"), nullSafeClassName(cacheStatistics.getClass())) .withDetail(cacheRegionStatisticsKey(regionName, "hit-count"), cacheStatistics.getHitCount()) .withDetail(cacheRegionStatisticsKey(regionName, "hit-ratio"), cacheStatistics.getHitRatio()) .withDetail(cacheRegionStatisticsKey(regionName, "last-accessed-time"), cacheStatistics.getLastAccessedTime()) .withDetail(cacheRegionStatisticsKey(regionName, "last-modified-time"), cacheStatistics.getLastModifiedTime()) .withDetail(cacheRegionStatisticsKey(regionName, "miss-count"), cacheStatistics.getMissCount())); }; }
Example 6
Source File: ElasticHealthIndicator.java From elastic-rest-spring-wrapper with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { List<String> downClusters = clusterService.getAvailableClusters().stream().filter(cluster -> { ClusterHealth clusterHealth = clusterService.checkClusterHealth(cluster); return "red".equals(clusterHealth.getStatus()); }). collect(Collectors.toList()); if (downClusters.isEmpty()) { builder.up(); } else { builder.down(); builder.withDetail("downClusterNames", Arrays.toString(downClusters.toArray())); } }
Example 7
Source File: DubboHealthIndicator.java From dubbo-spring-boot-starter with Apache License 2.0 | 6 votes |
@Override public void doHealthCheck(Health.Builder builder) throws Exception { boolean up = true; for (ClassIdBean classIdBean : ConsumerSubscribeListener.SUBSCRIBEDINTERFACES_SET) { Object service = DubboConsumerAutoConfiguration.getDubboReference(classIdBean); EchoService echoService = (EchoService) service; if (echoService != null) { try { echoService.$echo("Hello"); builder.withDetail(classIdBean.toString(), Status.UP.getCode()); } catch (Throwable t) { up = false; builder.withDetail(classIdBean.toString(), Status.DOWN.getCode() + ", message: " + t.getMessage()); } } } if (up) { builder.up(); } else { builder.down(); } }
Example 8
Source File: EurekaHealthCheckHandlerTests.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Bean public HealthIndicator healthIndicator() { return new AbstractHealthIndicator() { @Override protected void doHealthCheck(Health.Builder builder) throws Exception { builder.down(); } }; }
Example 9
Source File: MyAbstractHealthIndicator.java From springboot-learning-experience with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { int code = check(); if (code != 0) { builder.down().withDetail("code", code).withDetail("version", VERSION).build(); } builder.withDetail("code", code) .withDetail("version", VERSION).up().build(); }
Example 10
Source File: SidecarHealthIndicator.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { URI uri = this.sidecarProperties.getHealthCheckUrl(); if (uri == null) { builder.up(); return; } ResponseEntity<Map<String, Object>> exchange = this.restTemplate.exchange(uri, HttpMethod.GET, null, new ParameterizedTypeReference<Map<String, Object>>() { }); Map<String, Object> map = exchange.getBody(); if (map == null) { this.getWarning(builder); return; } Object status = map.get("status"); if (status instanceof String) { builder.status(status.toString()); } else { this.getWarning(builder); } } catch (Exception e) { builder.down().withDetail("error", e.getMessage()); } }
Example 11
Source File: ZookeeperHealthIndicator.java From kafka-graphs with Apache License 2.0 | 5 votes |
@Override public Mono<Health> health() { Health.Builder builder = new Health.Builder(); if (curator.getZookeeperClient().isConnected()) { builder.up(); } else { builder.down(); } return Mono.just(builder.build()); }
Example 12
Source File: EtcdHealthIndicator.java From spring-cloud-etcd with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { String version = client.getVersion(); builder.withDetail("version", version).up(); } catch (Exception e) { builder.down(e); } }
Example 13
Source File: GeodeRegionsHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getGemFireCache().isPresent()) { Set<Region<?, ?>> rootRegions = getGemFireCache() .map(GemFireCache::rootRegions) .orElseGet(Collections::emptySet); builder.withDetail("geode.cache.regions", rootRegions.stream() .filter(Objects::nonNull) .map(Region::getFullPath) .sorted() .collect(Collectors.toList())); builder.withDetail("geode.cache.regions.count", rootRegions.stream().filter(Objects::nonNull).count()); rootRegions.stream() .filter(Objects::nonNull) .forEach(region -> getGemfireRegionHealthIndicatorConsumers().accept(region, builder)); builder.up(); return; } builder.unknown(); }
Example 14
Source File: CassandraHealthIndicator.java From gpmr with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { log.debug("Initializing Cassandra health indicator"); try { ResultSet results = session.execute(validationStmt.bind()); if (results.isExhausted()) { builder.up(); } else { builder.up().withDetail("version", results.one().getString(0)); } } catch (Exception e) { log.debug("Cannot connect to Cassandra cluster. Error: {}", e); builder.down(e); } }
Example 15
Source File: GeodeIndexesHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getApplicationContext().isPresent()) { Map<String, Index> indexes = getApplicationContext() .map(it -> it.getBeansOfType(Index.class)) .orElseGet(Collections::emptyMap); builder.withDetail("geode.index.count", indexes.size()); indexes.values().stream() .filter(Objects::nonNull) .forEach(index -> { String indexName = index.getName(); builder.withDetail(indexKey(indexName, "from-clause"), index.getFromClause()) .withDetail(indexKey(indexName, "indexed-expression"), index.getIndexedExpression()) .withDetail(indexKey(indexName, "projection-attributes"), index.getProjectionAttributes()) .withDetail(indexKey(indexName, "region"), toRegionPath(index.getRegion())) .withDetail(indexKey(indexName, "type"), String.valueOf(index.getType())); IndexStatistics indexStatistics = index.getStatistics(); if (indexStatistics != null) { builder.withDetail(indexStatisticsKey(indexName, "number-of-bucket-indexes"), indexStatistics.getNumberOfBucketIndexes()) .withDetail(indexStatisticsKey(indexName, "number-of-keys"), indexStatistics.getNumberOfKeys()) .withDetail(indexStatisticsKey(indexName, "number-of-map-index-keys"), indexStatistics.getNumberOfMapIndexKeys()) .withDetail(indexStatisticsKey(indexName, "number-of-values"), indexStatistics.getNumberOfValues()) .withDetail(indexStatisticsKey(indexName, "number-of-updates"), indexStatistics.getNumUpdates()) .withDetail(indexStatisticsKey(indexName, "read-lock-count"), indexStatistics.getReadLockCount()) .withDetail(indexStatisticsKey(indexName, "total-update-time"), indexStatistics.getTotalUpdateTime()) .withDetail(indexStatisticsKey(indexName, "total-uses"), indexStatistics.getTotalUses()); } }); builder.up(); return; } builder.unknown(); }
Example 16
Source File: GeodeAsyncEventQueuesHealthIndicatorUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
public void testHealthCheckFailsWhenGemFireCacheIsInvalid(GemFireCache gemfireCache) throws Exception { GeodeAsyncEventQueuesHealthIndicator healthIndicator = gemfireCache != null ? new GeodeAsyncEventQueuesHealthIndicator(gemfireCache) : new GeodeAsyncEventQueuesHealthIndicator(); Health.Builder builder = new Health.Builder(); healthIndicator.doHealthCheck(builder); Health health = builder.build(); assertThat(health).isNotNull(); assertThat(health.getDetails()).isEmpty(); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); }
Example 17
Source File: GeodePoolsHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getGemFireCache().filter(CacheUtils::isClient).isPresent()) { Map<String, Pool> pools = nullSafeMap(findAllPools()); builder.withDetail("geode.pool.count", pools.size()); pools.values().stream() .filter(Objects::nonNull) .forEach(pool -> { String poolName = pool.getName(); builder.withDetail(poolKey(poolName, "destroyed"), toYesNoString(pool.isDestroyed())) .withDetail(poolKey(poolName, "free-connection-timeout"), pool.getFreeConnectionTimeout()) .withDetail(poolKey(poolName, "idle-timeout"), pool.getIdleTimeout()) .withDetail(poolKey(poolName, "load-conditioning-interval"), pool.getLoadConditioningInterval()) .withDetail(poolKey(poolName, "locators"), toCommaDelimitedHostAndPortsString(pool.getLocators())) .withDetail(poolKey(poolName, "max-connections"), pool.getMaxConnections()) .withDetail(poolKey(poolName, "min-connections"), pool.getMinConnections()) .withDetail(poolKey(poolName, "multi-user-authentication"), toYesNoString(pool.getMultiuserAuthentication())) .withDetail(poolKey(poolName, "online-locators"), toCommaDelimitedHostAndPortsString(pool.getOnlineLocators())) .withDetail(poolKey(poolName, "ping-interval"), pool.getPingInterval()) .withDetail(poolKey(poolName, "pr-single-hop-enabled"), toYesNoString(pool.getPRSingleHopEnabled())) .withDetail(poolKey(poolName, "read-timeout"), pool.getReadTimeout()) .withDetail(poolKey(poolName, "retry-attempts"), pool.getRetryAttempts()) .withDetail(poolKey(poolName, "server-group"), pool.getServerGroup()) .withDetail(poolKey(poolName, "servers"), toCommaDelimitedHostAndPortsString(pool.getServers())) .withDetail(poolKey(poolName, "socket-buffer-size"), pool.getSocketBufferSize()) .withDetail(poolKey(poolName, "statistic-interval"), pool.getStatisticInterval()) .withDetail(poolKey(poolName, "subscription-ack-interval"), pool.getSubscriptionAckInterval()) .withDetail(poolKey(poolName, "subscription-enabled"), toYesNoString(pool.getSubscriptionEnabled())) .withDetail(poolKey(poolName, "subscription-message-tracking-timeout"), pool.getSubscriptionMessageTrackingTimeout()) .withDetail(poolKey(poolName, "subscription-redundancy"), pool.getSubscriptionRedundancy()); //.withDetail(poolKey(poolName, "thread-local-connections"), toYesNoString(pool.getThreadLocalConnections())); getGemFireCache() .map(ClientCache.class::cast) .filter(CacheUtils::isDurable) .ifPresent(it -> builder.withDetail(poolKey(poolName, "pending-event-count"), pool.getPendingEventCount())); }); builder.up(); return; } builder.unknown(); }
Example 18
Source File: GeodeCacheServersHealthIndicatorUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
private void testHealthCheckFailsWhenGemFireCacheIsInvalid(GemFireCache gemfireCache) throws Exception { GeodeCacheServersHealthIndicator healthIndicator = gemfireCache != null ? new GeodeCacheServersHealthIndicator(gemfireCache) : new GeodeCacheServersHealthIndicator(); Health.Builder builder = new Health.Builder(); healthIndicator.doHealthCheck(builder); Health health = builder.build(); assertThat(health).isNotNull(); assertThat(health.getDetails()).isEmpty(); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); }
Example 19
Source File: GeodeContinuousQueriesHealthIndicatorUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 3 votes |
@Test public void healthCheckFailsWhenContinuousQueryListenerContainerIsNotPresent() throws Exception { GeodeContinuousQueriesHealthIndicator healthIndicator = new GeodeContinuousQueriesHealthIndicator(); Health.Builder builder = new Health.Builder(); healthIndicator.doHealthCheck(builder); Health health = builder.build(); assertThat(health).isNotNull(); assertThat(health.getDetails()).isEmpty(); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); }
Example 20
Source File: GeodeIndexesHealthIndicatorUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 3 votes |
@Test public void healthCheckFailsWhenApplicationContextContainsIsNotPresent() throws Exception { GeodeIndexesHealthIndicator healthIndicator = new GeodeIndexesHealthIndicator(); Health.Builder builder = new Health.Builder(); healthIndicator.doHealthCheck(builder); Health health = builder.build(); assertThat(health).isNotNull(); assertThat(health.getDetails()).isEmpty(); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); }