【发布时间】:2018-01-09 14:42:10
【问题描述】:
我正在尝试在我的 wildfly-swarm 2017.12.1 应用程序中实现一个微配置文件 HealthCheck。
这里是
@Health
@Dependent
public class SystemHealthChecker extends AbstractHealthChecker {
@Override
public HealthCheckResponse call() {
boolean up;
Runtime runtime = Runtime.getRuntime();
long freeMemory = runtime.freeMemory();
long totalMemory = runtime.totalMemory();
double percentageFree = freeMemory*100/totalMemory;
if(percentageFree < 10.0){
up = false;
}else{
up = true;
}
Map<String, String> attributes = new HashMap<>();
attributes.put("Total Memory", totalMemory+"");
attributes.put("Free Memory", freeMemory+"");
attributes.put("Percentage Free Memory", percentageFree+"%");
HealthCheckResponse response = getResponse("System-Check", attributes, up);
return response;
}
}
AbstractHealthChecker如下:
public abstract class AbstractHealthChecker implements HealthCheck {
protected HealthCheckResponse getResponse(String name, Map<String, String> data, boolean up){
HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named(name);
responseBuilder.state(up);
for(String key: data.keySet()){
responseBuilder.withData(key, data.get(key));
}
responseBuilder.withData("Date", new Date().toString());
return responseBuilder.build();
}
}
它应该检查系统的可用内存是否低于 10%,但这并不重要。 但是,当我启动应用程序时,我会收到警告:
2018-01-09 15:23:28,974 WARNING [ServiceLoader] (main) Could not load service class org.wildfly.swarm.microprofile.faulttolerance.deployment.HystrixExtension
2018-01-09 15:23:28,974 WARNING [ServiceLoader] (main) Could not load service class org.wildfly.swarm.microprofile.health.deployment.HealthExtension
2018-01-09 15:23:28,974 WARNING [ServiceLoader] (main) Could not load service class org.wildfly.swarm.microprofile.metrics.deployment.MetricCdiInjectionExtension
2018-01-09 15:23:28,975 WARNING [ServiceLoader] (main) Could not load service class org.wildfly.swarm.cdi.config.deployment.InjectConfigViewExtension
2018-01-09 15:23:28,975 WARNING [ServiceLoader] (main) Could not load service class org.wildfly.swarm.microprofile.jwtauth.deployment.auth.cdi.MPJWTExtension
/health 端点上的 System-Check 也没有真正的输出,我只得到以下内容
{
"outcome": "UP",
"checks": []
}
所以我想,我的 HealthCheck 没有找到。 我使用以下分数。 任何想法,出了什么问题?
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>ejb</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>microprofile</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>logging</artifactId>
</dependency>
【问题讨论】:
-
您的
getResponse()看起来如何?可以在这里找到适合我的代码:github.com/pilhuhn/microprofile-demo/blob/master/src/main/java/… -
它在我忘记添加的
AbstractHealthChecker中。我已经改变了它。中间的抽象类是问题的原因。
标签: health-monitoring wildfly-swarm