本文整理汇总了Java中com.codahale.metrics.health.HealthCheck类的典型用法代码示例。如果您正苦于以下问题:Java HealthCheck类的具体用法?Java HealthCheck怎么用?Java HealthCheck使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HealthCheck类属于com.codahale.metrics.health包,在下文中一共展示了HealthCheck类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
/**
Health check
@return 204 if healthy otherwise 500
*/
@GET
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@Path("check")
public Response check()
{
for (HealthStatus healthCheck : m_healthCheckService.getChecks())
{
HealthCheck.Result result = healthCheck.execute();
if (!result.isHealthy())
{
return setHeaders(Response.status(Response.Status.INTERNAL_SERVER_ERROR)).build();
}
}
return setHeaders(Response.status(m_healthyResponse)).build();
}
示例2: healthCheckHandler
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
public static Handler healthCheckHandler(
HealthCheckRegistry healthCheckRegistry, ObjectMapper mapper) {
Preconditions.checkState(healthCheckRegistry != null);
Preconditions.checkState(mapper != null);
SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks();
return xrpcRequest ->
Recipes.newResponseOk(
xrpcRequest
.getAlloc()
.directBuffer()
.writeBytes(
mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(healthChecks)),
Recipes.ContentType.Application_Json);
}
示例3: scheduleHealthChecks
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
public void scheduleHealthChecks(
EventLoopGroup workerGroup, int initialDelay, int delay, TimeUnit timeUnit) {
for (Map.Entry<String, HealthCheck> entry : healthCheckMap.entrySet()) {
healthCheckRegistry.register(entry.getKey(), entry.getValue());
}
workerGroup.scheduleWithFixedDelay(
new Runnable() {
@Override
public void run() {
healthCheckRegistry.runHealthChecks(workerGroup);
}
},
initialDelay,
delay,
timeUnit);
}
示例4: getHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Override
public HealthCheck.Result getHealth() {
try {
HBaseAdmin.checkHBaseAvailable(configuration);
return HealthCheck.Result.builder()
.healthy()
.withMessage("HBase running on:")
.withDetail("quorum", quorum)
.withDetail("clientPort", clientPort)
.withDetail("znodeParent", znodeParent)
.build();
} catch (Exception e) {
return HealthCheck.Result.builder()
.unhealthy(e)
.build();
}
}
示例5: getHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Override
public HealthCheck.Result getHealth() {
HealthCheck.ResultBuilder builder = HealthCheck.Result.builder();
long nonRunningProcessorCount = processors.stream()
.filter(processor -> !processor.getRunState().equals(RunState.RUNNING))
.count();
if (!runState.equals(RunState.RUNNING) || nonRunningProcessorCount > 0) {
builder.unhealthy();
} else {
builder.healthy();
}
builder.withDetail("runState", runState.name());
builder.withDetail("processorCount", processors.size());
builder.withDetail("processors", processors.stream()
.collect(HasHealthCheck.buildTreeMapCollector(
StatisticsAggregationProcessor::getName,
StatisticsAggregationProcessor::produceHealthCheckSummary)));
return builder.build();
}
示例6: getHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Override
public HealthCheck.Result getHealth() {
switch (runState) {
case RUNNING:
return HealthCheck.Result.builder()
.healthy()
.withMessage(runState.toString())
.withDetail("status", produceHealthCheckSummary())
.build();
default:
return HealthCheck.Result.builder()
.unhealthy()
.withMessage(runState.toString())
.withDetail("status", produceHealthCheckSummary())
.build();
}
}
示例7: getHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Override
public HealthCheck.Result getHealth() {
HealthCheck.ResultBuilder builder = HealthCheck.Result.builder();
long nonRunningProcessorCount = processors.stream()
.filter(processor -> !processor.getRunState().equals(RunState.RUNNING))
.count();
if (!runState.equals(RunState.RUNNING) || nonRunningProcessorCount > 0) {
builder.unhealthy();
} else {
builder.healthy();
}
builder.withDetail("runState", runState.name());
builder.withDetail("processorCount", processors.size());
builder.withDetail("processors", processors.stream()
.collect(HasHealthCheck.buildTreeMapCollector(
StatisticsFlatMappingProcessor::getName,
StatisticsFlatMappingProcessor::produceHealthCheckSummary)));
return builder.build();
}
示例8: getHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Override
public HealthCheck.Result getHealth() {
if (stroomPropertyService == null) {
return HealthCheck.Result.unhealthy("stroomPropertyService has not been initialised");
} else {
try {
//use a treeMap so the props are sorted on output
return HealthCheck.Result.builder()
.withMessage("Available")
.withDetail("properties", new TreeMap<>(stroomPropertyService.getAllProperties()))
.build();
} catch (Exception e) {
return HealthCheck.Result.unhealthy(e);
}
}
}
示例9: getHealthChecks
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
public Map<String, HealthCheck> getHealthChecks() {
return Collections.singletonMap(
JOB_MANAGER_JOB_QUEUE_OVERFLOW_HEALTHCHECK,
new HealthCheck() {
@Override
protected Result check() throws Exception {
final int queueSize = jobQueue.size();
if (queueSize < JOB_MANAGER_MAX_JOB_QUEUE_OVERFLOW_THRESHOLD) {
return Result.healthy(format("Queue contains %s entries", queueSize));
} else {
return Result.unhealthy(format(
"%s entries in job queue: this exceeds the warning threshold (%s)",
queueSize,
JOB_MANAGER_MAX_JOB_QUEUE_OVERFLOW_THRESHOLD));
}
}
});
}
示例10: testGetHealthChecksReturnsAHealthCheckForJobQueueOverflowing
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Test
public void testGetHealthChecksReturnsAHealthCheckForJobQueueOverflowing() {
final CancelablePromise<JobExecutionResult> executorPromise = new SimpleCancelablePromise<>();
final JobManager jobManager = createManagerWith(MockJobExecutor.thatUses(executorPromise));
final Map<String, HealthCheck> healthChecks = jobManager.getHealthChecks();
assertThat(healthChecks).containsKeys(JOB_MANAGER_JOB_QUEUE_OVERFLOW_HEALTHCHECK);
assertThat(healthChecks.get(JOB_MANAGER_JOB_QUEUE_OVERFLOW_HEALTHCHECK)).isNotNull();
final HealthCheck jobQueueHealthCheck = healthChecks.get(JOB_MANAGER_JOB_QUEUE_OVERFLOW_HEALTHCHECK);
assertThat(jobQueueHealthCheck.execute().isHealthy());
for(int i = 0; i < JOB_MANAGER_MAX_JOB_QUEUE_OVERFLOW_THRESHOLD * 2; i++) {
// These won't finish because we never resolve the promise
jobManager.submit(STANDARD_VALID_REQUEST);
}
assertThat(jobQueueHealthCheck.execute().isHealthy()).isFalse();
}
示例11: testZkHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Test
public void testZkHealth() throws Exception {
final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
client.start();
client.blockUntilConnected();
final HealthCheck check = new KafkaHealthCheck(client);
final HealthCheck.Result res = check.execute();
assertFalse(res.isHealthy());
assertTrue(res.getMessage().contains("Error fetching kafka broker list"));
client.createContainers("/brokers/ids");
final HealthCheck.Result res2 = check.execute();
assertFalse(res2.isHealthy());
assertEquals("No Kafka brokers are connected.", res2.getMessage());
client.createContainers("/brokers/ids/1");
final HealthCheck.Result res3 = check.execute();
assertTrue(res3.isHealthy());
}
示例12: testZkHealth
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
@Test
public void testZkHealth() throws Exception {
final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
client.start();
client.blockUntilConnected();
final HealthCheck check = new ZookeeperHealthCheck(client);
final HealthCheck.Result res = check.execute();
assertFalse(res.isHealthy());
assertEquals("Zookeeper not properly initialized", res.getMessage());
client.createContainers(ZNODE_COORDINATION);
final HealthCheck.Result res2 = check.execute();
assertTrue(res2.isHealthy());
}
示例13: status
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
/**
Returns the status of each health check.
@return 200
*/
@GET
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
@Path("status")
public Response status()
{
List<String> messages = new ArrayList<String>();
for (HealthStatus healthCheck : m_healthCheckService.getChecks())
{
HealthCheck.Result result = healthCheck.execute();
if (result.isHealthy())
{
messages.add(healthCheck.getName() + ": OK");
}
else
{
messages.add(healthCheck.getName() + ": FAIL");
}
}
GenericEntity<List<String>> entity = new GenericEntity<List<String>>(messages)
{
};
return setHeaders(Response.ok(entity)).build();
}
示例14: main
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
public static void main(String[] args) {
/*
* Init connection pools. They auto register their own health checks.
*/
ConnectionPools.getProcessing();
ConnectionPools.getTransactional();
// Assume some global HttpClient.
OkHttpClient client = new OkHttpClient.Builder().build();
HttpUrl passingPath = HttpUrl.parse("http://localhost:8080/ping");
HealthCheck passing = new ExternalServiceHealthCheck(client, passingPath);
HealthChecks.getHealthCheckRegistry().register("ping", passing);
// Since this route doesn't exist it will respond with 404 and should fail the check.
HttpUrl failingPath = HttpUrl.parse("http://localhost:8080/failingPath");
HealthCheck failing = new ExternalServiceHealthCheck(client, failingPath);
HealthChecks.getHealthCheckRegistry().register("shouldFail", failing);
// Once again pull in a bunch of common middleware.
SimpleServer server = SimpleServer.simpleServer(Middleware.common(ROUTES));
server.start();
}
示例15: healthCheckCommand
import com.codahale.metrics.health.HealthCheck; //导入依赖的package包/类
private String healthCheckCommand(IMessage message, OptionSet optionSet) {
StringBuilder response = new StringBuilder();
if (healthCheckRegistry.getNames().isEmpty()) {
return "No health checks registered";
}
Map<String, HealthCheck.Result> resultMap = healthCheckRegistry.runHealthChecks();
response.append("*Health check results*\n");
for (Map.Entry<String, HealthCheck.Result> entry : resultMap.entrySet()) {
HealthCheck.Result result = entry.getValue();
String msg = result.getMessage();
Throwable t = result.getError();
response.append(result.isHealthy() ? "[Healthy]" : "[Caution]")
.append(" **").append(entry.getKey()).append("** ")
.append(msg != null ? msg : "")
.append(t != null ? " and exception: *" + t.getMessage() + "*" : "").append("\n");
}
return response.toString();
}