use of org.eclipse.microprofile.health.HealthCheck in project Payara by payara.
the class HealthCheckService method collectChecks.
private Map<String, List<HealthCheckResponse>> collectChecks(MonitoringDataCollector collector, Map<String, Set<HealthCheck>> checks, Map<String, Set<String>> collected) {
Map<String, List<HealthCheckResponse>> statusByApp = new HashMap<>();
for (Entry<String, Set<HealthCheck>> entry : checks.entrySet()) {
String appName = entry.getKey();
MonitoringDataCollector appCollector = collector.group(appName);
for (HealthCheck check : entry.getValue()) {
HealthCheckResponse response = performHealthCheckInApplicationContext(appName, check);
String metric = response.getName();
Set<String> appCollected = collected.get(appName);
// prevent adding same check more then once, unfortunately we have to run it to find that out
if (appCollected == null || !appCollected.contains(metric)) {
statusByApp.computeIfAbsent(appName, key -> new ArrayList<>()).add(response);
collectUpDown(appCollector, response);
if (response.getStatus() == Status.DOWN && response.getData().isPresent()) {
appCollector.annotate(metric, 0L, createAnnotation(response.getData().get()));
}
collected.computeIfAbsent(appName, key -> new HashSet<>()).add(metric);
}
}
}
return statusByApp;
}
use of org.eclipse.microprofile.health.HealthCheck in project wildfly by wildfly.
the class MicroProfileHealthReporterService method wrap.
static HealthCheck wrap(ServerProbe delegate) {
return new HealthCheck() {
@Override
public HealthCheckResponse call() {
ServerProbe.Outcome outcome = delegate.getOutcome();
HealthCheckResponseBuilder check = HealthCheckResponse.named(delegate.getName()).status(outcome.isSuccess());
if (outcome.getData().isDefined()) {
for (Property property : outcome.getData().asPropertyList()) {
check.withData(property.getName(), property.getValue().asString());
}
}
return check.build();
}
};
}
use of org.eclipse.microprofile.health.HealthCheck in project wildfly-swarm by wildfly-swarm.
the class HttpContexts method proxyRequestsCDI.
private void proxyRequestsCDI(HttpServerExchange exchange) {
Set<Object> procedures = monitor.getHealthDelegates();
if (procedures.isEmpty()) {
noHealthEndpoints(exchange);
return;
}
List<org.eclipse.microprofile.health.HealthCheckResponse> responses = new ArrayList<>();
for (Object procedure : procedures) {
org.eclipse.microprofile.health.HealthCheckResponse status = ((HealthCheck) procedure).call();
responses.add(status);
}
StringBuilder sb = new StringBuilder(LCURL);
sb.append("\"checks\": [\n");
int i = 0;
boolean failed = false;
for (org.eclipse.microprofile.health.HealthCheckResponse resp : responses) {
sb.append(toJson(resp));
if (!failed) {
failed = resp.getState() != HealthCheckResponse.State.UP;
}
if (i < responses.size() - 1) {
sb.append(",\n");
}
i++;
}
sb.append("],\n");
String outcome = failed ? "DOWN" : "UP";
sb.append("\"outcome\": \"" + outcome + "\"\n");
sb.append("}\n");
// send a response
if (failed) {
exchange.setStatusCode(503);
}
responseHeaders(exchange);
exchange.getResponseSender().send(sb.toString());
exchange.endExchange();
}
Aggregations