Search in sources :

Example 11 with MetricFilter

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

Example 12 with 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);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) Connection(java.sql.Connection) Metric(com.codahale.metrics.Metric) HikariConfig(com.zaxxer.hikari.HikariConfig) Test(org.junit.Test)

Example 13 with MetricFilter

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));
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricsModule(com.codahale.metrics.json.MetricsModule) TimeUnit(java.util.concurrent.TimeUnit) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with MetricFilter

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);
}
Also used : Histogram(com.codahale.metrics.Histogram) Arrays(java.util.Arrays) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) PortType(com.github.ambry.network.PortType) TestUtils(com.github.ambry.utils.TestUtils) Map(java.util.Map) Counter(com.codahale.metrics.Counter) MetricFilter(com.codahale.metrics.MetricFilter) LinkedList(java.util.LinkedList) Time(com.github.ambry.utils.Time) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Resource(com.github.ambry.clustermap.Resource) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) Pair(com.github.ambry.utils.Pair) Iterator(java.util.Iterator) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Metric(com.codahale.metrics.Metric) Set(java.util.Set) Utils(com.github.ambry.utils.Utils) Test(org.junit.Test) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) Collectors(java.util.stream.Collectors) RouterConfig(com.github.ambry.config.RouterConfig) List(java.util.List) MockTime(com.github.ambry.utils.MockTime) ReplicaId(com.github.ambry.clustermap.ReplicaId) Gauge(com.codahale.metrics.Gauge) Port(com.github.ambry.network.Port) Assert(org.junit.Assert) CachedHistogram(com.github.ambry.utils.CachedHistogram) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) PartitionId(com.github.ambry.clustermap.PartitionId) SortedMap(java.util.SortedMap) MetricRegistry(com.codahale.metrics.MetricRegistry) RouterConfig(com.github.ambry.config.RouterConfig) Gauge(com.codahale.metrics.Gauge) MetricFilter(com.codahale.metrics.MetricFilter) Iterator(java.util.Iterator) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 15 with MetricFilter

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);
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Metric(com.codahale.metrics.Metric)

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