use of com.codahale.metrics.Metric in project gerrit by GerritCodeReview.
the class ProcMetricModuleTest method get.
private <M extends Metric> M get(String name, Class<M> type) {
Metric m = registry.getMetrics().get(name);
assertThat(m).named(name).isNotNull();
assertThat(m).named(name).isInstanceOf(type);
@SuppressWarnings("unchecked") M result = (M) m;
return result;
}
use of com.codahale.metrics.Metric in project hive by apache.
the class CodahaleMetrics method close.
@Override
public void close() throws Exception {
if (reporters != null) {
for (Closeable reporter : reporters) {
reporter.close();
}
}
for (Map.Entry<String, Metric> metric : metricRegistry.getMetrics().entrySet()) {
metricRegistry.remove(metric.getKey());
}
timers.invalidateAll();
counters.invalidateAll();
meters.invalidateAll();
}
use of com.codahale.metrics.Metric in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricWait.
@Test
public void testMetricWait() throws SQLException {
MetricRegistry metricRegistry = new MetricRegistry();
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setMetricRegistry(metricRegistry);
config.setInitializationFailTimeout(Long.MAX_VALUE);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
ds.getConnection().close();
Timer timer = metricRegistry.getTimers(new MetricFilter() {
/** {@inheritDoc} */
@Override
public boolean matches(String name, Metric metric) {
return "testMetricWait.pool.Wait".equals(MetricRegistry.name("testMetricWait", "pool", "Wait"));
}
}).values().iterator().next();
assertEquals(1, timer.getCount());
assertTrue(timer.getMeanRate() > 0.0);
}
}
use of com.codahale.metrics.Metric in project HikariCP by brettwooldridge.
the class CodahaleHealthChecker method registerHealthChecks.
/**
* Register Dropwizard health checks.
*
* @param pool the pool to register health checks for
* @param hikariConfig the pool configuration
* @param registry the HealthCheckRegistry into which checks will be registered
*/
public static void registerHealthChecks(final HikariPool pool, final HikariConfig hikariConfig, final HealthCheckRegistry registry) {
final Properties healthCheckProperties = hikariConfig.getHealthCheckProperties();
final MetricRegistry metricRegistry = (MetricRegistry) hikariConfig.getMetricRegistry();
final long checkTimeoutMs = Long.parseLong(healthCheckProperties.getProperty("connectivityCheckTimeoutMs", String.valueOf(hikariConfig.getConnectionTimeout())));
registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "ConnectivityCheck"), new ConnectivityHealthCheck(pool, checkTimeoutMs));
final long expected99thPercentile = Long.parseLong(healthCheckProperties.getProperty("expected99thPercentileMs", "0"));
if (metricRegistry != null && expected99thPercentile > 0) {
SortedMap<String, Timer> timers = metricRegistry.getTimers(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.equals(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Wait"));
}
});
if (!timers.isEmpty()) {
final Timer timer = timers.entrySet().iterator().next().getValue();
registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Connection99Percent"), new Connection99Percent(timer, expected99thPercentile));
}
}
}
use of com.codahale.metrics.Metric in project metrics by dropwizard.
the class BufferPoolMetricSet method getMetrics.
@Override
public Map<String, Metric> getMetrics() {
final Map<String, Metric> gauges = new HashMap<String, Metric>();
for (String pool : POOLS) {
for (int i = 0; i < ATTRIBUTES.length; i++) {
final String attribute = ATTRIBUTES[i];
final String name = NAMES[i];
try {
final ObjectName on = new ObjectName("java.nio:type=BufferPool,name=" + pool);
mBeanServer.getMBeanInfo(on);
gauges.put(name(pool, name), new JmxAttributeGauge(mBeanServer, on, attribute));
} catch (JMException ignored) {
LOGGER.debug("Unable to load buffer pool MBeans, possibly running on Java 6");
}
}
}
return Collections.unmodifiableMap(gauges);
}
Aggregations