当前位置: 首页>>代码示例>>Java>>正文


Java Health类代码示例

本文整理汇总了Java中org.springframework.boot.actuate.health.Health的典型用法代码示例。如果您正苦于以下问题:Java Health类的具体用法?Java Health怎么用?Java Health使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Health类属于org.springframework.boot.actuate.health包,在下文中一共展示了Health类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: health

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:LearningSpringBootHealthIndicator.java

示例2: health

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:17,代码来源:MyHealthCheck.java

示例3: invoke

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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;
}
 
开发者ID:dm-drogeriemarkt,项目名称:extended-actuator-health-endpoints,代码行数:17,代码来源:ExtendedHealthMvcEndpoint.java

示例4: downWithExceptionHandling

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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));
}
 
开发者ID:dm-drogeriemarkt,项目名称:extended-actuator-health-endpoints,代码行数:26,代码来源:ExtendedHealthMvcEndpointUnitTest.java

示例5: appendProviderDetails

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
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());
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:18,代码来源:RequiredProvidersHealthCheck.java

示例6: doHealthCheck

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:VHAINNOVATIONS,项目名称:BCDS,代码行数:17,代码来源:JavaMailHealthIndicator.java

示例7: doHealthCheck

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:aatarasoff,项目名称:spring-cloud-marathon,代码行数:20,代码来源:MarathonHealthIndicator.java

示例8: doHealthCheck

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CamelHealthIndicator.java

示例9: doHealthCheck

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:21,代码来源:ResourceProvidersHealthIndicator.java

示例10: testDoHealthCheckSingleQueueCheckMetricException

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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"));
}
 
开发者ID:julian-eggers,项目名称:spring-rabbitmq-actuator,代码行数:19,代码来源:RabbitQueueCheckHealthIndicatorTest.java

示例11: newValueIsReturnedOnceTtlExpires

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:HealthMvcEndpointTests.java

示例12: doHealthCheck

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:22,代码来源:KubernetesHealthIndicator.java

示例13: health

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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();
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:21,代码来源:VaultHealthIndicator.java

示例14: getHealthBuilder

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
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();
	}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:17,代码来源:VaultHealthIndicator.java

示例15: taskHealthIndicator

import org.springframework.boot.actuate.health.Health; //导入依赖的package包/类
@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());
            }
        }
    };
}
 
开发者ID:ContainerSolutions,项目名称:mesosframework,代码行数:21,代码来源:TaskActuatorConfiguration.java


注:本文中的org.springframework.boot.actuate.health.Health类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。