Merge pull request #566 from wvuong/connection_timeout_metrics

Add metric for recording count and rate of connection timeouts
pull/577/head
Brett Wooldridge 9 years ago
commit 6eac710240

@ -35,6 +35,10 @@ public class MetricsTracker implements AutoCloseable
{
}
public void recordConnectionTimeout()
{
}
@Override
public void close()
{

@ -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<Integer>() {
@ -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;

@ -184,6 +184,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
}
logPoolState("Timeout failure ");
metricsTracker.recordConnectionTimeout();
String sqlState = null;
final Throwable originalException = getLastConnectionFailure();

@ -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
}
}
}

Loading…
Cancel
Save