added remove of ConnectionTimeoutRate and refactored metric names into constants (#698)

pull/882/head
Jack 9 years ago committed by Brett Wooldridge
parent a332a773d1
commit f7fbc841f4

@ -34,15 +34,24 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
private final Meter connectionTimeoutMeter;
private final MetricRegistry registry;
private static final String METRIC_CATEGORY = "pool";
private static final String METRIC_NAME_WAIT = "Wait";
private static final String METRIC_NAME_USAGE = "Usage";
private static final String METRIC_NAME_TIMEOUT_RATE = "ConnectionTimeoutRate";
private static final String METRIC_NAME_TOTAL_CONNECTIONS = "TotalConnections";
private static final String METRIC_NAME_IDLE_CONNECTIONS = "IdleConnections";
private static final String METRIC_NAME_ACTIVE_CONNECTIONS = "ActiveConnections";
private static final String METRIC_NAME_PENDING_CONNECTIONS = "PendingConnections";
public CodaHaleMetricsTracker(final String poolName, final PoolStats poolStats, final MetricRegistry registry)
{
this.poolName = poolName;
this.registry = registry;
this.connectionObtainTimer = registry.timer(MetricRegistry.name(poolName, "pool", "Wait"));
this.connectionUsage = registry.histogram(MetricRegistry.name(poolName, "pool", "Usage"));
this.connectionTimeoutMeter = registry.meter(MetricRegistry.name(poolName, "pool", "ConnectionTimeoutRate"));
this.connectionObtainTimer = registry.timer(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_WAIT));
this.connectionUsage = registry.histogram(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_USAGE));
this.connectionTimeoutMeter = registry.meter(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_TIMEOUT_RATE));
registry.register(MetricRegistry.name(poolName, "pool", "TotalConnections"),
registry.register(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_TOTAL_CONNECTIONS),
new Gauge<Integer>() {
@Override
public Integer getValue() {
@ -50,7 +59,7 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
}
});
registry.register(MetricRegistry.name(poolName, "pool", "IdleConnections"),
registry.register(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_IDLE_CONNECTIONS),
new Gauge<Integer>() {
@Override
public Integer getValue() {
@ -58,7 +67,7 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
}
});
registry.register(MetricRegistry.name(poolName, "pool", "ActiveConnections"),
registry.register(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_ACTIVE_CONNECTIONS),
new Gauge<Integer>() {
@Override
public Integer getValue() {
@ -66,7 +75,7 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
}
});
registry.register(MetricRegistry.name(poolName, "pool", "PendingConnections"),
registry.register(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_PENDING_CONNECTIONS),
new Gauge<Integer>() {
@Override
public Integer getValue() {
@ -79,12 +88,13 @@ public final class CodaHaleMetricsTracker extends MetricsTracker
@Override
public void close()
{
registry.remove(MetricRegistry.name(poolName, "pool", "Wait"));
registry.remove(MetricRegistry.name(poolName, "pool", "Usage"));
registry.remove(MetricRegistry.name(poolName, "pool", "TotalConnections"));
registry.remove(MetricRegistry.name(poolName, "pool", "IdleConnections"));
registry.remove(MetricRegistry.name(poolName, "pool", "ActiveConnections"));
registry.remove(MetricRegistry.name(poolName, "pool", "PendingConnections"));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_WAIT));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_USAGE));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_TIMEOUT_RATE));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_TOTAL_CONNECTIONS));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_IDLE_CONNECTIONS));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_ACTIVE_CONNECTIONS));
registry.remove(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_PENDING_CONNECTIONS));
}
/** {@inheritDoc} */

@ -0,0 +1,39 @@
package com.zaxxer.hikari.metrics.dropwizard;
import com.codahale.metrics.MetricRegistry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public class CodaHaleMetricsTrackerTest {
@Mock
public MetricRegistry mockMetricRegistry;
private CodaHaleMetricsTracker testee;
@Before
public void setup(){
testee = new CodaHaleMetricsTracker("mypool", null, mockMetricRegistry);
}
@Test
public void close() throws Exception {
testee.close();
verify(mockMetricRegistry).remove("mypool.pool.Wait");
verify(mockMetricRegistry).remove("mypool.pool.Usage");
verify(mockMetricRegistry).remove("mypool.pool.ConnectionTimeoutRate");
verify(mockMetricRegistry).remove("mypool.pool.TotalConnections");
verify(mockMetricRegistry).remove("mypool.pool.IdleConnections");
verify(mockMetricRegistry).remove("mypool.pool.ActiveConnections");
verify(mockMetricRegistry).remove("mypool.pool.PendingConnections");
}
}
Loading…
Cancel
Save