Search in sources :

Example 1 with HealthChecked

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

the class SqlConnectionProviderPlugin method checkTestSelect.

@HealthChecked(name = "testQuery", feature = "sqlDatabase")
default HealthMeasure checkTestSelect() {
    final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
    final String testQuery = getDataBase().getSqlDialect().getTestQuery();
    try {
        final SqlDataBaseManager sqlDataBaseManager = Home.getApp().getComponentSpace().resolve(SqlDataBaseManager.class);
        final SqlConnection connection = obtainConnection();
        try {
            sqlDataBaseManager.executeQuery(SqlStatement.builder(testQuery).build(), Integer.class, 1, connection);
        } finally {
            connection.release();
        }
        healthMeasureBuilder.withGreenStatus();
    } catch (final Exception e) {
        healthMeasureBuilder.withRedStatus(e.getMessage(), e);
    }
    return healthMeasureBuilder.build();
}
Also used : HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) SqlDataBaseManager(io.vertigo.database.sql.SqlDataBaseManager) SqlConnection(io.vertigo.database.sql.connection.SqlConnection) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Example 2 with HealthChecked

use of io.vertigo.commons.analytics.health.HealthChecked 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 3 with HealthChecked

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

the class JpaDataStorePlugin method checkJpaStore.

@HealthChecked(name = "testQuery", feature = "jpa")
public HealthMeasure checkJpaStore() {
    final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        getEntityManager().createNativeQuery("select 1", Integer.class).getFirstResult();
        healthMeasureBuilder.withGreenStatus();
    } catch (final Exception e) {
        healthMeasureBuilder.withRedStatus(e.getMessage(), e).build();
    }
    return healthMeasureBuilder.build();
}
Also used : HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VSystemException(io.vertigo.lang.VSystemException) SQLException(java.sql.SQLException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) PersistenceException(javax.persistence.PersistenceException) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Example 4 with HealthChecked

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

the class RedisConnector method checkRedisPing.

@HealthChecked(name = "ping", feature = "redis")
public HealthMeasure checkRedisPing() {
    final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
    try (Jedis jedis = getResource()) {
        final String result = jedis.ping();
        healthMeasureBuilder.withGreenStatus(result);
    } catch (final Exception e) {
        healthMeasureBuilder.withRedStatus(e.getMessage(), e);
    }
    return healthMeasureBuilder.build();
}
Also used : HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) Jedis(redis.clients.jedis.Jedis) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Example 5 with HealthChecked

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

the class RedisConnector method checkRedisIO.

@HealthChecked(name = "io", feature = "redis")
public HealthMeasure checkRedisIO() {
    final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
    try (Jedis jedis = getResource()) {
        jedis.set("vertigoHealthCheckIoKey", "vertigoHealthCheckIoValue");
        jedis.get("vertigoHealthCheckIoKey");
        jedis.del("vertigoHealthCheckIoKey");
        healthMeasureBuilder.withGreenStatus();
    } catch (final Exception e) {
        healthMeasureBuilder.withRedStatus(e.getMessage(), e);
    }
    return healthMeasureBuilder.build();
}
Also used : HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) Jedis(redis.clients.jedis.Jedis) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Aggregations

HealthChecked (io.vertigo.commons.analytics.health.HealthChecked)8 HealthMeasureBuilder (io.vertigo.commons.analytics.health.HealthMeasureBuilder)7 Jedis (redis.clients.jedis.Jedis)3 Home (io.vertigo.app.Home)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 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