use of com.codahale.metrics.MetricFilter in project storm by apache.
the class StormMetricRegistry method deregister.
public void deregister(Set<Metric> toRemove) {
MetricFilter metricFilter = new RemoveMetricFilter(toRemove);
for (TaskMetricRepo taskMetricRepo : taskMetrics.values()) {
taskMetricRepo.degister(metricFilter);
}
registry.removeMatching(metricFilter);
}
use of com.codahale.metrics.MetricFilter in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricUsage.
@Test
public void testMetricUsage() throws SQLException {
Assume.assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
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)) {
Connection connection = ds.getConnection();
UtilityElf.quietlySleep(250L);
connection.close();
Histogram histo = metricRegistry.getHistograms(new MetricFilter() {
/**
* {@inheritDoc}
*/
@Override
public boolean matches(String name, Metric metric) {
return "test.pool.Usage".equals(MetricRegistry.name("test", "pool", "Usage"));
}
}).values().iterator().next();
Assert.assertEquals(1, histo.getCount());
double seventyFifth = histo.getSnapshot().get75thPercentile();
Assert.assertTrue("Seventy-fith percentile less than 250ms: " + seventyFifth, seventyFifth >= 250.0);
}
}
use of com.codahale.metrics.MetricFilter in project metrics by dropwizard.
the class MetricsServlet method setupMetricsModule.
protected void setupMetricsModule(ServletContext context) {
final TimeUnit rateUnit = parseTimeUnit(context.getInitParameter(RATE_UNIT), TimeUnit.SECONDS);
final TimeUnit durationUnit = parseTimeUnit(context.getInitParameter(DURATION_UNIT), TimeUnit.SECONDS);
final boolean showSamples = Boolean.parseBoolean(context.getInitParameter(SHOW_SAMPLES));
MetricFilter filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
if (filter == null) {
filter = MetricFilter.ALL;
}
this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter));
}
use of com.codahale.metrics.MetricFilter in project ambry by linkedin.
the class AdaptiveOperationTrackerTest method customPercentilesMetricsRegistryTest.
/**
* Test that {@link NonBlockingRouterMetrics} can correctly register custom percentiles. An example of metric name is:
* "com.github.ambry.router.GetOperation.LocalColoLatencyMs.91.0.thPercentile"
*/
@Test
public void customPercentilesMetricsRegistryTest() {
// test that if custom percentile is not set, no corresponding metrics would be generated.
MetricRegistry metricRegistry = routerMetrics.getMetricRegistry();
MetricFilter filter = new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.endsWith("thPercentile");
}
};
SortedMap<String, Gauge> gauges = metricRegistry.getGauges(filter);
assertTrue("No gauges should be created because custom percentile is not set", gauges.isEmpty());
// test that dedicated gauges are correctly created for custom percentiles.
String customPercentiles = "0.91,0.97";
RouterConfig routerConfig = createRouterConfig(false, 1, 1, 6, customPercentiles, true);
String[] percentileArray = customPercentiles.split(",");
Arrays.sort(percentileArray);
List<String> sortedPercentiles = Arrays.stream(percentileArray).map(p -> String.valueOf(Double.parseDouble(p) * 100)).collect(Collectors.toList());
routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
gauges = routerMetrics.getMetricRegistry().getGauges(filter);
// Note that each percentile creates 4 metrics (GetBlobInfo/GetBlob joins LocalColo/CrossColo). So, the total number of
// metrics should equal to 4 * (# of given custom percentiles)
assertEquals("The number of custom percentile gauge doesn't match", sortedPercentiles.size() * 4, gauges.size());
Iterator mapItor = gauges.keySet().iterator();
Iterator<String> listItor = sortedPercentiles.iterator();
while (listItor.hasNext()) {
String gaugeName = (String) mapItor.next();
String percentileStr = listItor.next();
assertTrue("The gauge name doesn't match", gaugeName.endsWith(percentileStr + ".thPercentile"));
}
// reset router metrics to clean up registered custom percentile metrics
routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, defaultRouterConfig);
}
use of com.codahale.metrics.MetricFilter in project Singularity by HubSpot.
the class SingularityGraphiteReporter method start.
public void start() {
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);
}
Aggregations