Search in sources :

Example 21 with MetricFilter

use of com.codahale.metrics.MetricFilter in project Singularity by HubSpot.

the class SingularityGraphiteReporterManaged method start.

@Override
public void start() throws Exception {
    if (!graphiteConfiguration.isEnabled()) {
        LOG.info("Not reporting data points to graphite.");
        return;
    }
    final String prefix = buildGraphitePrefix();
    final Map<String, String> tags = buildGraphiteTags();
    LOG.info("Reporting data points to graphite server {}:{} every {} seconds with prefix '{}', predicates '{}', and tags '{}'.", graphiteConfiguration.getHostname(), graphiteConfiguration.getPort(), graphiteConfiguration.getPeriodSeconds(), prefix, JavaUtils.COMMA_JOINER.join(graphiteConfiguration.getPredicates()), JavaUtils.COMMA_EQUALS_MAP_JOINER.join(tags));
    graphite = new GraphiteWithTags(new InetSocketAddress(graphiteConfiguration.getHostname(), graphiteConfiguration.getPort()), SocketFactory.getDefault(), Charsets.UTF_8, tags);
    final GraphiteReporter.Builder reporterBuilder = GraphiteReporter.forRegistry(registry);
    if (!Strings.isNullOrEmpty(prefix)) {
        reporterBuilder.prefixedWith(prefix);
    }
    if (!graphiteConfiguration.getPredicates().isEmpty()) {
        reporterBuilder.filter(new MetricFilter() {

            @Override
            public boolean matches(String name, Metric metric) {
                for (String predicate : graphiteConfiguration.getPredicates()) {
                    if (name.startsWith(predicate)) {
                        return true;
                    }
                }
                return false;
            }
        });
    }
    reporter = reporterBuilder.build(graphite);
    reporter.start(graphiteConfiguration.getPeriodSeconds(), TimeUnit.SECONDS);
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Metric(com.codahale.metrics.Metric)

Example 22 with MetricFilter

use of com.codahale.metrics.MetricFilter in project sidewinder by srotya.

the class MetricsRegistryService method getInstance.

public MetricRegistry getInstance(String key) {
    MetricRegistry reg = registry.get(key);
    if (reg == null) {
        reg = new MetricRegistry();
        if (!DISABLE_SELF_MONITORING) {
            SidewinderDropwizardReporter reporter = new SidewinderDropwizardReporter(reg, key, new MetricFilter() {

                @Override
                public boolean matches(String name, Metric metric) {
                    return true;
                }
            }, TimeUnit.SECONDS, TimeUnit.SECONDS, engine, es);
            reporter.start(1, TimeUnit.SECONDS);
            this.reporter.put(key, reporter);
        }
        registry.put(key, reg);
    }
    return reg;
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) SidewinderDropwizardReporter(com.srotya.sidewinder.core.SidewinderDropwizardReporter)

Example 23 with MetricFilter

use of com.codahale.metrics.MetricFilter in project incubator-gobblin by apache.

the class MetricFiltersTest method andTest.

@Test
public void andTest() {
    MetricFilter trueMetricFilter = mock(MetricFilter.class);
    when(trueMetricFilter.matches(any(String.class), any(Metric.class))).thenReturn(true);
    MetricFilter falseMetricFilter = mock(MetricFilter.class);
    when(falseMetricFilter.matches(any(String.class), any(Metric.class))).thenReturn(false);
    Assert.assertTrue(MetricFilters.and(trueMetricFilter, trueMetricFilter).matches("", mock(Metric.class)));
    Assert.assertFalse(MetricFilters.and(trueMetricFilter, falseMetricFilter).matches("", mock(Metric.class)));
    Assert.assertFalse(MetricFilters.and(falseMetricFilter, trueMetricFilter).matches("", mock(Metric.class)));
    Assert.assertFalse(MetricFilters.and(falseMetricFilter, falseMetricFilter).matches("", mock(Metric.class)));
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) Test(org.testng.annotations.Test)

Example 24 with MetricFilter

use of com.codahale.metrics.MetricFilter in project HikariCP by brettwooldridge.

the class TestMetrics method testMetricWait.

@Test
public void testMetricWait() throws SQLException {
    MetricRegistry metricRegistry = new MetricRegistry();
    HikariConfig config = new HikariConfig();
    config.setMinimumIdle(1);
    config.setMaximumPoolSize(1);
    config.setMetricRegistry(metricRegistry);
    config.setInitializationFailFast(false);
    config.setPoolName("test");
    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 "test.pool.Wait".equals(MetricRegistry.name("test", "pool", "Wait"));
            }
        }).values().iterator().next();
        Assert.assertEquals(1, timer.getCount());
        Assert.assertTrue(timer.getMeanRate() > 0.0);
    }
}
Also used : 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) Test(org.junit.Test)

Example 25 with MetricFilter

use of com.codahale.metrics.MetricFilter 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)

Aggregations

MetricFilter (com.codahale.metrics.MetricFilter)28 Metric (com.codahale.metrics.Metric)17 MetricRegistry (com.codahale.metrics.MetricRegistry)12 Counter (com.codahale.metrics.Counter)5 Map (java.util.Map)5 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)5 Gauge (com.codahale.metrics.Gauge)4 Histogram (com.codahale.metrics.Histogram)4 Timer (com.codahale.metrics.Timer)4 Test (org.junit.Test)4 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Meter (com.codahale.metrics.Meter)2 MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MethodHandles (java.lang.invoke.MethodHandles)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2