Fix #203 unregister metrics at shutdown.

pull/201/merge
Brett Wooldridge 10 years ago
parent 03542eb579
commit 26d6f254db

@ -30,12 +30,14 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
{
private final Timer connectionObtainTimer;
private final Histogram connectionUsage;
private final MetricRegistry registry;
public CodaHaleMetricsTracker(final HikariPool pool, final MetricRegistry registry) {
super(pool);
connectionObtainTimer = registry.timer(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
connectionUsage = registry.histogram(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
this.registry = registry;
this.connectionObtainTimer = registry.timer(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
this.connectionUsage = registry.histogram(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
registry.register(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "TotalConnections"),
new CachedGauge<Integer>(10, TimeUnit.SECONDS) {
@ -74,6 +76,18 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
});
}
/** {@inheritDoc} */
@Override
public void close()
{
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "TotalConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "IdleConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "ActiveConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "PendingConnections"));
}
/** {@inheritDoc} */
@Override
public Context recordConnectionRequest(final long requestTime)

@ -35,17 +35,19 @@ public class MetricsTracker
this.pool = pool;
}
/** {@inheritDoc} */
public MetricsContext recordConnectionRequest(long requestTime)
{
return NO_CONTEXT;
}
/** {@inheritDoc} */
public void recordConnectionUsage(final PoolBagEntry bagEntry)
{
}
public void close()
{
}
/**
* A base instance of a MetricsContext. Classes extending this class should exhibit the
* behavior of "starting" a timer upon contruction, and "stopping" the timer when the

@ -259,6 +259,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
logPoolState("After shutdown ");
unregisterMBeans(configuration, this);
metricsTracker.close();
}
}

@ -30,12 +30,14 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
{
private final Timer connectionObtainTimer;
private final Histogram connectionUsage;
private final MetricRegistry registry;
public CodaHaleMetricsTracker(final HikariPool pool, final MetricRegistry registry) {
super(pool);
connectionObtainTimer = registry.timer(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
connectionUsage = registry.histogram(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
this.registry = registry;
this.connectionObtainTimer = registry.timer(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
this.connectionUsage = registry.histogram(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
registry.register(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "TotalConnections"),
new CachedGauge<Integer>(10, TimeUnit.SECONDS) {
@ -74,6 +76,18 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
});
}
/** {@inheritDoc} */
@Override
public void close()
{
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Wait"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "Usage"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "TotalConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "IdleConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "ActiveConnections"));
registry.remove(MetricRegistry.name(pool.getConfiguration().getPoolName(), "pool", "PendingConnections"));
}
/** {@inheritDoc} */
@Override
public Context recordConnectionRequest(final long requestTime)

@ -35,17 +35,19 @@ public class MetricsTracker
this.pool = pool;
}
/** {@inheritDoc} */
public MetricsContext recordConnectionRequest(long requestTime)
{
return NO_CONTEXT;
}
/** {@inheritDoc} */
public void recordConnectionUsage(final PoolBagEntry bagEntry)
{
}
public void close()
{
}
/**
* A base instance of a MetricsContext. Classes extending this class should exhibit the
* behavior of "starting" a timer upon contruction, and "stopping" the timer when the

@ -256,6 +256,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
logPoolState("After shutdown ");
unregisterMBeans(configuration, this);
metricsTracker.close();
}
}

Loading…
Cancel
Save