@ -16,10 +16,6 @@
package com.zaxxer.hikari.metrics.dropwizard ;
import java.sql.Connection ;
import java.sql.SQLException ;
import java.util.concurrent.TimeUnit ;
import com.codahale.metrics.MetricRegistry ;
import com.codahale.metrics.Timer ;
import com.codahale.metrics.health.HealthCheck ;
@ -27,6 +23,10 @@ import com.codahale.metrics.health.HealthCheckRegistry;
import com.zaxxer.hikari.HikariConfig ;
import com.zaxxer.hikari.pool.HikariPool ;
import java.sql.Connection ;
import java.sql.SQLException ;
import java.util.concurrent.TimeUnit ;
/ * *
* Provides Dropwizard HealthChecks . Two health checks are provided :
* < ul >
@ -54,13 +54,16 @@ public final class CodahaleHealthChecker
public static void registerHealthChecks ( final HikariPool pool , final HikariConfig hikariConfig , final HealthCheckRegistry registry )
{
final var healthCheckProperties = hikariConfig . getHealthCheckProperties ( ) ;
final var metricRegistry = ( MetricRegistry ) hikariConfig . getMetricRegistry ( ) ;
final var checkTimeoutMs = Long . parseLong ( healthCheckProperties . getProperty ( "connectivityCheckTimeoutMs" , String . valueOf ( hikariConfig . getConnectionTimeout ( ) ) ) ) ;
registry . register ( MetricRegistry . name ( hikariConfig . getPoolName ( ) , "pool" , "ConnectivityCheck" ) , new ConnectivityHealthCheck ( pool , checkTimeoutMs ) ) ;
final var expected99thPercentile = Long . parseLong ( healthCheckProperties . getProperty ( "expected99thPercentileMs" , "0" ) ) ;
if ( metricRegistry ! = null & & expected99thPercentile > 0 ) {
final Object metricRegistryObj = hikariConfig . getMetricRegistry ( ) ;
if ( expected99thPercentile > 0 & & metricRegistryObj instanceof MetricRegistry ) {
final var metricRegistry = ( MetricRegistry ) metricRegistryObj ;
var timers = metricRegistry . getTimers ( ( name , metric ) - > name . equals ( MetricRegistry . name ( hikariConfig . getPoolName ( ) , "pool" , "Wait" ) ) ) ;
if ( ! timers . isEmpty ( ) ) {