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);
}
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;
}
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)));
}
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);
}
}
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));
}
}
}
Aggregations