Search in sources :

Example 1 with HealthMeasure

use of io.vertigo.commons.analytics.health.HealthMeasure in project vertigo by KleeGroup.

the class DaemonManagerImpl method checkDaemonsExecs.

@HealthChecked(name = "lastExecs", feature = "daemons")
public HealthMeasure checkDaemonsExecs() {
    final List<DaemonStat> daemonStats = getStats();
    final long failureCount = daemonStats.stream().filter(// to have a real indicator we use only daemon that have been executed at least once
    daemonStat -> daemonStat.getCount() > 0).filter(daemonStat -> !daemonStat.isLastExecSuccess()).count();
    // ---
    final HealthMeasureBuilder healthMeasure = HealthMeasure.builder();
    if (failureCount == 0) {
        return healthMeasure.withGreenStatus().build();
    } else if (failureCount < daemonStats.size()) {
        return healthMeasure.withYellowStatus("At least one daemon failed", null).build();
    }
    return healthMeasure.withRedStatus("All daemons failed", null).build();
}
Also used : HealthChecked(io.vertigo.commons.analytics.health.HealthChecked) DaemonDefinition(io.vertigo.commons.daemon.DaemonDefinition) DaemonStat(io.vertigo.commons.daemon.DaemonStat) DaemonManager(io.vertigo.commons.daemon.DaemonManager) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) AnalyticsManager(io.vertigo.commons.analytics.AnalyticsManager) ClassUtil(io.vertigo.util.ClassUtil) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) List(java.util.List) Stream(java.util.stream.Stream) Activeable(io.vertigo.core.component.Activeable) SimpleDefinitionProvider(io.vertigo.core.definition.SimpleDefinitionProvider) Assertion(io.vertigo.lang.Assertion) Component(io.vertigo.core.component.Component) HealthMeasure(io.vertigo.commons.analytics.health.HealthMeasure) AopPlugin(io.vertigo.core.component.AopPlugin) Daemon(io.vertigo.commons.daemon.Daemon) DaemonScheduled(io.vertigo.commons.daemon.DaemonScheduled) HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) DaemonStat(io.vertigo.commons.daemon.DaemonStat) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Example 2 with HealthMeasure

use of io.vertigo.commons.analytics.health.HealthMeasure in project vertigo by KleeGroup.

the class HealthAnalyticsUtil method createHealthCheckDefinitions.

/**
 * Registers all methods annotated with @Suscriber on the object
 * @param componentId componentId to check
 * @param component Component to check
 * @param aopPlugin Aop plugin use for unwrap
 * @return List of HealthCheckDefinition
 */
public static List<HealthCheckDefinition> createHealthCheckDefinitions(final String componentId, final Component component, final AopPlugin aopPlugin) {
    Assertion.checkNotNull(component);
    // -- we construct a map of feature by componentId
    final Map<String, String> featureByComponentId = new HashMap<>();
    Home.getApp().getConfig().getModuleConfigs().forEach(moduleConfig -> moduleConfig.getComponentConfigs().forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName())));
    // 1. search all methods
    return Stream.of(aopPlugin.unwrap(component).getClass().getMethods()).filter(method -> method.isAnnotationPresent(HealthChecked.class)).map(method -> {
        final HealthChecked healthChecked = method.getAnnotation(HealthChecked.class);
        Assertion.checkArgument(HealthMeasure.class.equals(method.getReturnType()), "health check methods of class {0} must return a HealthMeasure instead of {1}", component.getClass(), method.getReturnType());
        Assertion.checkArgument(method.getName().startsWith("check"), "health check methods of class {0} must start with check", component.getClass());
        Assertion.checkArgument(method.getParameterTypes().length == 0, "health check methods of class {0} must not have any parameter", component.getClass());
        // -----
        // 2. For each method register a listener
        // we remove # because it doesn't comply with definition naming rule
        final String healthCheckDefinitionName = "HCHK_" + StringUtil.camelToConstCase(componentId.replaceAll("#", "")) + "$" + StringUtil.camelToConstCase(method.getName());
        return new HealthCheckDefinition(healthCheckDefinitionName, healthChecked.name(), componentId, featureByComponentId.get(componentId), healthChecked.feature(), () -> (HealthMeasure) ClassUtil.invoke(component, method));
    }).collect(Collectors.toList());
}
Also used : HealthChecked(io.vertigo.commons.analytics.health.HealthChecked) HashMap(java.util.HashMap) Instant(java.time.Instant) ClassUtil(io.vertigo.util.ClassUtil) Collectors(java.util.stream.Collectors) HealthStatus(io.vertigo.commons.analytics.health.HealthStatus) Home(io.vertigo.app.Home) List(java.util.List) Stream(java.util.stream.Stream) StringUtil(io.vertigo.util.StringUtil) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) HealthCheck(io.vertigo.commons.analytics.health.HealthCheck) Component(io.vertigo.core.component.Component) HealthMeasure(io.vertigo.commons.analytics.health.HealthMeasure) AopPlugin(io.vertigo.core.component.AopPlugin) HealthCheckDefinition(io.vertigo.commons.analytics.health.HealthCheckDefinition) HealthMeasure(io.vertigo.commons.analytics.health.HealthMeasure) HashMap(java.util.HashMap) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked) HealthCheckDefinition(io.vertigo.commons.analytics.health.HealthCheckDefinition)

Aggregations

Home (io.vertigo.app.Home)2 HealthChecked (io.vertigo.commons.analytics.health.HealthChecked)2 HealthMeasure (io.vertigo.commons.analytics.health.HealthMeasure)2 AopPlugin (io.vertigo.core.component.AopPlugin)2 Component (io.vertigo.core.component.Component)2 Assertion (io.vertigo.lang.Assertion)2 ClassUtil (io.vertigo.util.ClassUtil)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 AnalyticsManager (io.vertigo.commons.analytics.AnalyticsManager)1 HealthCheck (io.vertigo.commons.analytics.health.HealthCheck)1 HealthCheckDefinition (io.vertigo.commons.analytics.health.HealthCheckDefinition)1 HealthMeasureBuilder (io.vertigo.commons.analytics.health.HealthMeasureBuilder)1 HealthStatus (io.vertigo.commons.analytics.health.HealthStatus)1 Daemon (io.vertigo.commons.daemon.Daemon)1 DaemonDefinition (io.vertigo.commons.daemon.DaemonDefinition)1 DaemonManager (io.vertigo.commons.daemon.DaemonManager)1 DaemonScheduled (io.vertigo.commons.daemon.DaemonScheduled)1 DaemonStat (io.vertigo.commons.daemon.DaemonStat)1