com.nitorcreations.nflow.metrics.DatabaseConnectionHealthCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nflow-metrics Show documentation
Show all versions of nflow-metrics Show documentation
Integrate http://metrics.dropwizard.io/ with nFlow
package com.nitorcreations.nflow.metrics;
import com.codahale.metrics.health.HealthCheck;
import com.nitorcreations.nflow.engine.service.HealthCheckService;
/**
* Check that connection to nflow database can be made.
*/
public class DatabaseConnectionHealthCheck extends HealthCheck {
private final HealthCheckService healthCheckService;
public DatabaseConnectionHealthCheck(HealthCheckService healthCheckService) {
this.healthCheckService = healthCheckService;
}
@Override
protected Result check() {
try {
healthCheckService.checkDatabaseConnection();
return HealthCheck.Result.healthy("Connection to nFlow database is OK.");
} catch(Exception e) {
return HealthCheck.Result.unhealthy(e);
}
}
}