Java 类org.springframework.boot.actuate.health.Health 实例源码

项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:LearningSpringBootHealthIndicator.java   
@Override
public Health health() {
    try {
        URL url =
            new URL("http://greglturnquist.com/learning-spring-boot");
        HttpURLConnection conn =
            (HttpURLConnection) url.openConnection();
        int statusCode = conn.getResponseCode();
        if (statusCode >= 200 && statusCode < 300) {
            return Health.up().build();
        } else {
            return Health.down()
                .withDetail("HTTP Status Code", statusCode)
                .build();
        }
    } catch (IOException e) {
        return Health.down(e).build();
    }
}
项目:camel-springboot    文件:MyHealthCheck.java   
@Override
public Health health() {
    String hostname="unknown";

    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ex) {
        log.warn("Failed to get hostname.",ex);
    }

    return Health.up()
            .withDetail("hostname", hostname)
            .withDetail("localTime", LocalDateTime.now())
            .withDetail("date", new Date()) // uses spring.jackson.date-format
            .build();
}
项目:extended-actuator-health-endpoints    文件:ExtendedHealthMvcEndpoint.java   
@RequestMapping(method = RequestMethod.GET, produces = {
        ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
        MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public Object invoke(HttpServletRequest request) {
    if (!getDelegate().isEnabled()) {
        // Shouldn't happen because the request mapping should not be registered
        return getDisabledResponse();
    }
    Health health = getDelegate().invoke();
    HttpStatus status = this.statusMapping.get(health.getStatus().getCode());
    if (status != null) {
        return new ResponseEntity<>(health, status);
    }
    return health;
}
项目:extended-actuator-health-endpoints    文件:ExtendedHealthMvcEndpointUnitTest.java   
@Test
public void downWithExceptionHandling() throws Exception {

    HealthAggregator healthAggregator = mock(HealthAggregator.class);
    ApplicationAliveIndicator healthIndicator = mock(ApplicationAliveIndicator.class);
    when(healthIndicator.health()).thenThrow(new RuntimeException("fooException"));
    Map<String, ApplicationAliveIndicator> healthIndicators = new LinkedHashMap<>();
    healthIndicators.put("foo", healthIndicator);

    when(applicationContext.getBeansOfType(ApplicationAliveIndicator.class)).thenReturn(healthIndicators);


    extendedHealthEndpoint = new AliveHealthEndpoint("healthIndicatorfoo", healthAggregator);
    extendedHealthEndpoint.setApplicationContext(applicationContext);

    this.extendedHealthMvcEndpoint = new ExtendedHealthMvcEndpoint(this.extendedHealthEndpoint);

    ResponseEntity<Health> result = (ResponseEntity<Health>) this.extendedHealthMvcEndpoint.invoke(null);

    Map<String, Object> expectedHealthDetails = new LinkedHashMap<>();
    expectedHealthDetails.put("error", "java.lang.RuntimeException: fooException");
    assertThat(result.getBody().getDetails(), is(expectedHealthDetails));
    assertThat(result.getStatusCode(), is(HttpStatus.SERVICE_UNAVAILABLE));
    assertThat(result.getBody().getStatus(), is(Status.DOWN));
}
项目:smarti    文件:RequiredProvidersHealthCheck.java   
private void appendProviderDetails(Health.Builder builder, String name, Processor processor) {
    final Health.Builder sub = new Health.Builder(Status.UP);
    if (processor != null) {
        sub
                .withDetail("key", processor.getKey())
                .withDetail("name", processor.getName())
                .withDetail("class", processor.getClass().getName())
                ;
    } else {
        sub.outOfService();
        if (requiredProvidersHealthCheckProperties.isFailOnMissing() &&
                requiredProvidersHealthCheckProperties.getFailIfMissing().getOrDefault(name, true)) {
            builder.down();
        }
    }
    builder.withDetail(name, sub.build());
}
项目:BCDS    文件:JavaMailHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    log.debug("Initializing JavaMail health indicator");
    try {
        javaMailSender.getSession().getTransport().connect(javaMailSender.getHost(),
                javaMailSender.getPort(),
                javaMailSender.getUsername(),
                javaMailSender.getPassword());

        builder.up();

    } catch (MessagingException e) {
        log.debug("Cannot connect to e-mail server. Error: {}", e.getMessage());
        builder.down(e);
    }
}
项目:spring-cloud-marathon    文件:MarathonHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    try {
        GetServerInfoResponse serverInfo = client.getServerInfo();
        List<App> apps = client.getApps().getApps();
        builder.up()
                .withDetail("services", apps)
                .withDetail("name", serverInfo.getName())
                .withDetail("leader", serverInfo.getLeader())
                .withDetail("http_port", serverInfo.getHttp_config().getHttp_port())
                .withDetail("https_port", serverInfo.getHttp_config().getHttps_port())
                .withDetail("hostname", serverInfo.getMarathon_config().getHostname())
                .withDetail("local_port_min", serverInfo.getMarathon_config().getLocal_port_min())
                .withDetail("local_port_max", serverInfo.getMarathon_config().getLocal_port_max());
    }
    catch (Exception e) {
        builder.down(e);
    }
}
项目:Camel    文件:CamelHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    if (camelContext == null) {
        builder.unknown();
    } else {
        builder.withDetail("version", camelContext.getVersion());
        builder.withDetail("contextStatus", camelContext.getStatus().name());
        if (camelContext.getStatus().isStarted()) {
            builder.up();
        } else if (camelContext.getStatus().isStopped()) {
            builder.down();
        } else {
            builder.unknown();
        }
    }
}
项目:fiat    文件:ResourceProvidersHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
  boolean isDown = false;
  for (HealthTrackable provider : providers) {
    builder.withDetail(provider.getClass().getSimpleName(), provider.getHealthTracker().getHealthView());
    isDown = isDown || !provider.getHealthTracker().isProviderHealthy();
  }

  if (isDown) {
    if (previousHealthCheckIsUp.getAndSet(false)) {
      log.warn("Server is now UNHEALTHY");
    }
    builder.down();
  } else {
    if (!previousHealthCheckIsUp.getAndSet(true)) {
      log.info("Server is now HEALTHY. Hooray!");
    }
    builder.up();
  }
}
项目:spring-rabbitmq-actuator    文件:RabbitQueueCheckHealthIndicatorTest.java   
@Test
public void testDoHealthCheckSingleQueueCheckMetricException() throws Exception
{
    Queue queue = generateQueue("test");
    healthIndicator.addQueueCheck(queue, 10000, 2);

    propertiesManager.request(queue);
    PowerMock.expectLastCall().andThrow(new RuntimeException());

    PowerMock.replayAll();
    Builder builder = new Builder(Status.OUT_OF_SERVICE);
    healthIndicator.doHealthCheck(builder);
    PowerMock.verifyAll();

    Health health = builder.build();
    Assert.assertEquals(Status.DOWN, health.getStatus());
    Assert.assertNull(health.getDetails().get("test"));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HealthMvcEndpointTests.java   
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.isSensitive()).willReturn(false);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(null);
    assertThat(result instanceof Health).isTrue();
    assertThat(((Health) result).getStatus() == Status.UP).isTrue();
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null);
    @SuppressWarnings("unchecked")
    Health health = ((ResponseEntity<Health>) result).getBody();
    assertThat(health.getStatus() == Status.DOWN).isTrue();
}
项目:spring-cloud-kubernetes    文件:KubernetesHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    try {
        Pod current = utils.currentPod().get();
        if (current != null) {
            builder.up()
                    .withDetail("inside", true)
                    .withDetail("namespace", current.getMetadata().getNamespace())
                    .withDetail("podName", current.getMetadata().getName())
                    .withDetail("podIp", current.getStatus().getPodIP())
                    .withDetail("serviceAccount", current.getSpec().getServiceAccountName())
                    .withDetail("nodeName", current.getSpec().getNodeName())
                    .withDetail("hostIp", current.getStatus().getHostIP());
        } else {
            builder.up()
                    .withDetail("inside", false);
        }
    } catch (Exception e) {
        builder.down(e);
    }
}
项目:spring-cloud-vault    文件:VaultHealthIndicator.java   
@Override
public Health health() {

    try {

        VaultHealth vaultHealthResponse = vaultOperations.opsForSys().health();

        Builder healthBuilder = getHealthBuilder(vaultHealthResponse);

        if (StringUtils.hasText(vaultHealthResponse.getVersion())) {
            healthBuilder = healthBuilder.withDetail("version",
                    vaultHealthResponse.getVersion());
        }

        return healthBuilder.build();
    }
    catch (Exception e) {
        return Health.down(e).build();
    }
}
项目:spring-cloud-vault    文件:VaultHealthIndicator.java   
private Builder getHealthBuilder(VaultHealth vaultHealthResponse) {

        if (!vaultHealthResponse.isInitialized()) {
            return Health.down().withDetail("state", "Vault uninitialized");
        }

        if (vaultHealthResponse.isSealed()) {
            return Health.down().withDetail("state", "Vault sealed");
        }

        if (vaultHealthResponse.isStandby()) {
            return Health.up().withDetail("state", "Vault in standby");
        }

        return Health.up();
    }
项目:mesosframework    文件:TaskActuatorConfiguration.java   
@Bean
public HealthIndicator taskHealthIndicator() {
    return new AbstractHealthIndicator() {
        @Override
        protected void doHealthCheck(Health.Builder builder) throws Exception {
            if (correctNumberOfInstances()) {
                builder.up();
            } else {
                builder.down();
            }
            builder.withDetail("mesos.resources.count", instanceCount.getCount());
            builder.withDetail("instances", stateRepository.allTaskInfos().size());

            for (Protos.TaskState taskState : Protos.TaskState.values()) {
                Map<String, Protos.TaskStatus> state = getTasksForState(taskState);
                builder.withDetail(taskState.name(), state.size());
            }
        }
    };
}
项目:elastic-rest-spring-wrapper    文件:ElasticHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    ClusterHealth clusterHealth = clusterService.checkClusterHealth();

    switch (clusterHealth.getStatus()) {
        case "green":
        case "yellow":
            builder.up();
            break;
        case "red":
        default:
            builder.down();
            break;
    }
    builder.withDetail("clusterName", clusterHealth.getClusterName());
    builder.withDetail("numberOfNodes", clusterHealth.getNumberOfNodes());
}
项目:spring-boot-concourse    文件:HealthMvcEndpointTests.java   
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.isSensitive()).willReturn(false);
    given(this.endpoint.invoke())
            .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(null);
    assertThat(result instanceof Health).isTrue();
    assertThat(((Health) result).getStatus() == Status.UP).isTrue();
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(null);
    @SuppressWarnings("unchecked")
    Health health = ((ResponseEntity<Health>) result).getBody();
    assertThat(health.getStatus() == Status.DOWN).isTrue();
}
项目:cmc-claim-store    文件:GovNotifyHealthIndicator.java   
@Override
public Health health() {
    try {
        client.getNotifications(null, null, "fake_ref", null);
        return Health.up().build();
    } catch (Exception exc) {
        LOGGER.error("Error on GOV Notify service healthcheck", exc);
        return Health.down(exc).build();
    }
}
项目:hiatus-spring-boot    文件:HiatusHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    if (hiatusEndpoint.isPaused()) {
        builder.outOfService();
    } else {
        builder.up();
    }
    builder.withDetail(HiatusEndpoint.FIELD_NAME_PAUSED, hiatusEndpoint.isPaused())
            .withDetail(HiatusEndpoint.FIELD_NAME_COUNT, hiatusEndpoint.getCount());
}
项目:spring-boot-graph-day    文件:JanusGraphHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder)
        throws Exception {

    if (hasConnection()) {
        builder.up();
    } else {
        builder.down();
    }
}
项目:TOSCAna    文件:TransformerHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    List<String> loadedPlugins = new ArrayList<>();
    pluginService.getSupportedPlatforms().forEach(e -> loadedPlugins.add(e.id));
    builder.withDetail(INSTALLED_PLUGINS_KEY, loadedPlugins);
    builder.withDetail(RUNNING_TRANSFORMATIONS_KEY,
        getTransformationInfoForState(TransformationState.TRANSFORMING));
    builder.withDetail(ERRORED_TRANSFORMATIONS_KEY,
        getTransformationInfoForState(TransformationState.ERROR));
    builder.up().build();
}
项目:sentry    文件:GameServerHealthIndicator.java   
@Override
public Health health() {
    /*
    Perform a series of checks:
    - Servers must be up (0 < delay < 1000 and State == GOOD)
    - Servers must have the latest version
    - Servers must have a valid RCON password (non-null)
     */
    Map<String, Object> details = new LinkedHashMap<>();
    List<GameServer> unresponsive = gameServerService.findUnhealthyServers();
    if (!unresponsive.isEmpty()) {
        details.put("unresponsive", unresponsive.stream()
            .map(GameServer::toString)
            .collect(Collectors.toList()));
    }
    List<GameServer> outdated = gameServerService.findOutdatedServers();
    if (!outdated.isEmpty()) {
        details.put("outdated", outdated.stream()
            .map(GameServer::toString)
            .collect(Collectors.toList()));
    }
    List<GameServer> missingRcon = gameServerService.findServersWithoutRcon();
    if (!missingRcon.isEmpty()) {
        details.put("missingRcon", missingRcon.stream()
            .map(GameServer::toString)
            .collect(Collectors.toList()));
    }
    Health.Builder builder;
    if (details.isEmpty()) {
        builder = Health.up();
        gameServerService.getSummary().forEach(builder::withDetail);
    } else {
        builder = Health.outOfService();
        details.forEach(builder::withDetail);
    }
    return builder.build();
}
项目:sentry    文件:BotHealthIndicator.java   
@Override
public Health health() {
    int count = 0;
    int ready = 0;
    Map<String, Object> details = new LinkedHashMap<>();
    for (Map.Entry<Bot, IDiscordClient> entry : clientRegistry.getClients().entrySet()) {
        count++;
        Map<String, Object> bot = new LinkedHashMap<>();
        IDiscordClient client = entry.getValue();
        if (client.isReady()) {
            ready++;
            bot.put("status", "UP");
            bot.put("id", client.getOurUser().getStringID());
            bot.put("name", client.getOurUser().getName());
            bot.put("shards", client.getShardCount());
            bot.put("guilds", client.getGuilds().size());
            bot.put("channels", client.getChannels().size());
            bot.put("users", client.getUsers().size());
            bot.put("roles", client.getRoles().size());
        } else if (client.isLoggedIn()) {
            bot.put("status", "OUT_OF_SERVICE");
        } else {
            bot.put("status", "DOWN");
        }
        details.put(entry.getKey().getName(), bot);
    }
    Health.Builder builder = count == 0 ? Health.unknown() : (count == ready ? Health.up() : Health.outOfService());
    details.put("count", count);
    details.put("ready", ready);
    details.forEach(builder::withDetail);
    return builder.build();
}
项目:sentry    文件:CacheHealthIndicator.java   
@Override
public Health health() {
    Map<String, Map<String, Object>> caches = cacheManager.getCacheNames().stream()
        .map(name -> (GuavaCache) cacheManager.getCache(name))
        .map(cache -> buildStats(cache.getName(), cache.getNativeCache()))
        .collect(Collectors.toMap(stats -> (String) stats.get("name"), stats -> stats));
    Health.Builder builder = Health.up()
        .withDetail("count", caches.size());
    caches.forEach(builder::withDetail);
    return builder.build();
}
项目:Your-Microservice    文件:SystemInstanceStatusServiceImpl.java   
/**
 * Perform our Health check of checking a connection to ODB.
 *
 * @return Health of our Component
 */
@Override
public Health health() {
    synchronized(LOCK) {
        if (yourMSBulletinBroadcastNotification.
                getYourBulletin().getCloudStatus().equalsIgnoreCase(YourBulletin.CloudStatusType.OK.toString())) {
            return Health.up().withDetail(HEALTH_KEY, getCurrentSystemInstanceStatusBulletin()).build();
        }
        return Health.status(yourMSBulletinBroadcastNotification.getYourBulletin().getCloudStatus())
                .withDetail(HEALTH_KEY, getCurrentSystemInstanceStatusBulletin()).build();
    }
}
项目:basic-spring-boot-server    文件:StatusResource.java   
@Override
public Health health() {
    int errorCode = check();
    if (errorCode != 0) {
        return Health.down().withDetail("Error Code", errorCode).build();
    }
    return Health.up().build();
}
项目:spring-cloud-dataflow-metrics-collector    文件:CaffeineHealthIndicator.java   
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    CacheStats stats = this.cache.stats();
    builder.up().withDetail("evictionCount", stats.evictionCount());
    builder.up().withDetail("hitRate", stats.hitRate());
    builder.up().withDetail("missRate", stats.missRate());
    builder.up().withDetail("hitCount", stats.hitCount());
}
项目:xm-ms-timeline    文件:CassandraHealthIndicator.java   
@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);
    }
}
项目:illuminati    文件:HealthCheck.java   
@Override
public Health health() {
    boolean isOk = check();

    if (!isOk) {
        return Health.down().withDetail("Error Code", 10000).build();
    }

    return Health.up().build();
}