use of io.vertigo.commons.analytics.health.HealthMeasureBuilder 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();
}
use of io.vertigo.commons.analytics.health.HealthMeasureBuilder 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();
}
use of io.vertigo.commons.analytics.health.HealthMeasureBuilder 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();
}
use of io.vertigo.commons.analytics.health.HealthMeasureBuilder 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();
}
use of io.vertigo.commons.analytics.health.HealthMeasureBuilder 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();
}
Aggregations