diff --git a/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java index ac52e84b..2a5563ff 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/MetricsTracker.java @@ -35,6 +35,10 @@ public class MetricsTracker implements AutoCloseable { } + public void recordConnectionTimeout() + { + } + @Override public void close() { diff --git a/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodaHaleMetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodaHaleMetricsTracker.java index 2c5be6ef..7829e7a6 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodaHaleMetricsTracker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodaHaleMetricsTracker.java @@ -18,8 +18,10 @@ package com.zaxxer.hikari.metrics.dropwizard; import java.util.concurrent.TimeUnit; +import com.codahale.metrics.Counter; import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; +import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import com.zaxxer.hikari.metrics.MetricsTracker; @@ -30,6 +32,8 @@ public final class CodaHaleMetricsTracker extends MetricsTracker private final String poolName; private final Timer connectionObtainTimer; private final Histogram connectionUsage; + private final Counter connectionTimeouts; + private final Meter connectionTimeoutMeter; private final MetricRegistry registry; public CodaHaleMetricsTracker(final String poolName, final PoolStats poolStats, final MetricRegistry registry) @@ -38,6 +42,8 @@ public final class CodaHaleMetricsTracker extends MetricsTracker this.registry = registry; this.connectionObtainTimer = registry.timer(MetricRegistry.name(poolName, "pool", "Wait")); this.connectionUsage = registry.histogram(MetricRegistry.name(poolName, "pool", "Usage")); + this.connectionTimeouts = registry.counter(MetricRegistry.name(poolName, "pool", "ConnectionTimeouts")); + this.connectionTimeoutMeter = registry.meter(MetricRegistry.name(poolName, "pool", "ConnectionTimeoutRate")); registry.register(MetricRegistry.name(poolName, "pool", "TotalConnections"), new Gauge() { @@ -98,6 +104,13 @@ public final class CodaHaleMetricsTracker extends MetricsTracker connectionUsage.update(elapsedBorrowedMillis); } + @Override + public void recordConnectionTimeout() + { + connectionTimeouts.inc(); + connectionTimeoutMeter.mark(); + } + public Timer getConnectionAcquisitionTimer() { return connectionObtainTimer; diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index d0906e17..273a5b92 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -184,6 +184,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL } logPoolState("Timeout failure "); + metricsTracker.recordConnectionTimeout(); String sqlState = null; final Throwable originalException = getLastConnectionFailure(); diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 0dab0642..521412ee 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -584,6 +584,10 @@ abstract class PoolBase poolEntry.lastBorrowed = now; tracker.recordConnectionAcquiredNanos(ClockSource.INSTANCE.elapsedNanos(startTime, now)); } + + void recordConnectionTimeout() { + tracker.recordConnectionTimeout(); + } } static final class NopMetricsTrackerDelegate extends MetricsTrackerDelegate @@ -605,5 +609,11 @@ abstract class PoolBase { // no-op } + + @Override + void recordConnectionTimeout() + { + // no-op + } } }