@Override
public HealthCheck create(final ServiceContext context) {
return new HealthCheck("Sufficient free connections in "+Geonet.Res.MAIN_DB) {
@Override
protected Result check() throws Exception {
Stats stats;
try {
stats = new Stats(context);
int free = stats.maxActive - stats.numActive;
double fivePercent = Math.max(2.0, ((double) stats.maxActive) * 0.01);
if (free < fivePercent) {
Result.unhealthy("There are insufficient free connections on database" + Geonet.Res.MAIN_DB
+ ". Connections free:" + free);