Search in sources :

Example 31 with Metric

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;
}
Also used : Metric(com.codahale.metrics.Metric)

Example 32 with Metric

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();
}
Also used : Closeable(java.io.Closeable) Metric(com.codahale.metrics.Metric) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 33 with Metric

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);
    }
}
Also used : TestElf.newHikariDataSource(com.zaxxer.hikari.pool.TestElf.newHikariDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricFilter(com.codahale.metrics.MetricFilter) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 34 with Metric

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));
        }
    }
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) Properties(java.util.Properties)

Example 35 with Metric

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);
}
Also used : JmxAttributeGauge(com.codahale.metrics.JmxAttributeGauge) HashMap(java.util.HashMap) JMException(javax.management.JMException) Metric(com.codahale.metrics.Metric) ObjectName(javax.management.ObjectName)

Aggregations

Metric (com.codahale.metrics.Metric)58 Test (org.junit.Test)27 MetricRegistry (com.codahale.metrics.MetricRegistry)16 Map (java.util.Map)16 HashMap (java.util.HashMap)13 Counter (com.codahale.metrics.Counter)10 Gauge (com.codahale.metrics.Gauge)10 Timer (com.codahale.metrics.Timer)10 MetricFilter (com.codahale.metrics.MetricFilter)8 MetricFilter (com.kixeye.chassis.support.metrics.MetricFilter)8 Meter (com.codahale.metrics.Meter)7 Histogram (com.codahale.metrics.Histogram)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 List (java.util.List)3 Random (java.util.Random)3 Collectors (java.util.stream.Collectors)3