Search in sources :

Example 6 with HealthCheck

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;
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) JsonWriterFactory(javax.json.JsonWriterFactory) Events(org.glassfish.api.event.Events) MonitoringWatchCollector(fish.payara.monitoring.collect.MonitoringWatchCollector) Map(java.util.Map) WebApplication(com.sun.enterprise.web.WebApplication) LIVENESS(fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheckServiceEvents(fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collections.emptyList(java.util.Collections.emptyList) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WARNING(java.util.logging.Level.WARNING) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) Optional(java.util.Optional) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) JsonObjectBuilder(javax.json.JsonObjectBuilder) Deployment(org.glassfish.internal.deployment.Deployment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) READINESS(fish.payara.microprofile.healthcheck.HealthCheckType.READINESS) JsonGenerator(javax.json.stream.JsonGenerator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JsonArrayBuilder(javax.json.JsonArrayBuilder) Globals(org.glassfish.internal.api.Globals) MonitoringData(fish.payara.monitoring.collect.MonitoringData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InvocationException(org.glassfish.api.invocation.InvocationException) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) BiConsumer(java.util.function.BiConsumer) Json(javax.json.Json) Collections.singletonMap(java.util.Collections.singletonMap) EventListener(org.glassfish.api.event.EventListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RunLevel(org.glassfish.hk2.runlevel.RunLevel) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebContainer(com.sun.enterprise.web.WebContainer) IOException(java.io.IOException) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) STARTUP(fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP) Status(org.eclipse.microprofile.health.HealthCheckResponse.Status) MonitoringWatchSource(fish.payara.monitoring.collect.MonitoringWatchSource) JsonWriter(javax.json.JsonWriter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ConfigListener(org.jvnet.hk2.config.ConfigListener) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) Set(java.util.Set) HashSet(java.util.HashSet) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 7 with HealthCheck

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();
        }
    };
}
Also used : ServerProbe(org.wildfly.extension.health.ServerProbe) HealthCheckResponseBuilder(org.eclipse.microprofile.health.HealthCheckResponseBuilder) HealthCheck(org.eclipse.microprofile.health.HealthCheck) Property(org.jboss.dmr.Property)

Example 8 with HealthCheck

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();
}
Also used : HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) ArrayList(java.util.ArrayList) HealthCheck(org.eclipse.microprofile.health.HealthCheck) HttpString(io.undertow.util.HttpString) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse)

Aggregations

HealthCheck (org.eclipse.microprofile.health.HealthCheck)8 ArrayList (java.util.ArrayList)3 HealthCheckResponse (org.eclipse.microprofile.health.HealthCheckResponse)3 WebApplication (com.sun.enterprise.web.WebApplication)2 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)2 WebContainer (com.sun.enterprise.web.WebContainer)2 LIVENESS (fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS)2 READINESS (fish.payara.microprofile.healthcheck.HealthCheckType.READINESS)2 STARTUP (fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP)2 PayaraHealthCheck (fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck)2 MicroprofileHealthCheckConfiguration (fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration)2 MonitoringData (fish.payara.monitoring.collect.MonitoringData)2 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 MonitoringDataSource (fish.payara.monitoring.collect.MonitoringDataSource)2 MonitoringWatchCollector (fish.payara.monitoring.collect.MonitoringWatchCollector)2 MonitoringWatchSource (fish.payara.monitoring.collect.MonitoringWatchSource)2 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)2 PayaraHealthCheckServiceEvents (fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 IOException (java.io.IOException)2