Search in sources :

Example 6 with MetricFilter

use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.

the class MetricUtils method toMaps.

/**
   * Convert selected metrics to maps or to flattened objects.
   * @param registry source of metrics
   * @param shouldMatchFilters metrics must match any of these filters
   * @param mustMatchFilter metrics must match this filter
   * @param propertyFilter limit what properties of a metric are returned
   * @param skipHistograms discard any {@link Histogram}-s and histogram parts of {@link Timer}-s.
   * @param skipAggregateValues discard internal values of {@link AggregateMetric}-s.
   * @param compact use compact representation for counters and gauges.
   * @param simple use simplified representation for complex metrics - instead of a (name, map)
   *             only the selected (name "." key, value) pairs will be produced.
   * @param consumer consumer that accepts produced objects
   */
public static void toMaps(MetricRegistry registry, List<MetricFilter> shouldMatchFilters, MetricFilter mustMatchFilter, PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String, Object> consumer) {
    final Map<String, Metric> metrics = registry.getMetrics();
    final SortedSet<String> names = registry.getNames();
    names.stream().filter(s -> shouldMatchFilters.stream().anyMatch(metricFilter -> metricFilter.matches(s, metrics.get(s)))).filter(s -> mustMatchFilter.matches(s, metrics.get(s))).forEach(n -> {
        Metric metric = metrics.get(n);
        convertMetric(n, metric, propertyFilter, skipHistograms, skipAggregateValues, compact, simple, consumer);
    });
}
Also used : Histogram(com.codahale.metrics.Histogram) SortedSet(java.util.SortedSet) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Meter(com.codahale.metrics.Meter) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Counter(com.codahale.metrics.Counter) PlatformManagedObject(java.lang.management.PlatformManagedObject) MetricFilter(com.codahale.metrics.MetricFilter) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) ExecutorService(java.util.concurrent.ExecutorService) AggregateMetric(org.apache.solr.metrics.AggregateMetric) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Metric(com.codahale.metrics.Metric) Snapshot(com.codahale.metrics.Snapshot) NamedList(org.apache.solr.common.util.NamedList) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) PropertyDescriptor(java.beans.PropertyDescriptor) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) Collections(java.util.Collections) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric)

Example 7 with MetricFilter

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

the class MetricContextTest method testGetMetricsWithFilter.

@Test(dependsOnMethods = "testGetMetrics")
@SuppressWarnings("unchecked")
public void testGetMetricsWithFilter() {
    MetricFilter filter = new MetricFilter() {

        @Override
        public boolean matches(String name, Metric metric) {
            return !name.equals(MetricContext.GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME);
        }
    };
    Map<String, Counter> counters = this.context.getCounters(filter);
    Assert.assertEquals(counters.size(), 1);
    Assert.assertTrue(counters.containsKey(RECORDS_PROCESSED));
    Map<String, Meter> meters = this.context.getMeters(filter);
    Assert.assertEquals(meters.size(), 1);
    Assert.assertTrue(meters.containsKey(RECORD_PROCESS_RATE));
    Map<String, Histogram> histograms = this.context.getHistograms(filter);
    Assert.assertEquals(histograms.size(), 1);
    Assert.assertTrue(histograms.containsKey(RECORD_SIZE_DISTRIBUTION));
    Map<String, Timer> timers = this.context.getTimers(filter);
    Assert.assertEquals(timers.size(), 1);
    Assert.assertTrue(timers.containsKey(TOTAL_DURATION));
    Map<String, Gauge> gauges = this.context.getGauges(filter);
    Assert.assertEquals(gauges.size(), 1);
    Assert.assertTrue(gauges.containsKey(QUEUE_SIZE));
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Gauge(com.codahale.metrics.Gauge) MetricFilter(com.codahale.metrics.MetricFilter) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Metric(com.codahale.metrics.Metric) Test(org.testng.annotations.Test)

Example 8 with MetricFilter

use of com.codahale.metrics.MetricFilter in project jackrabbit-oak by apache.

the class BenchmarkRunner method reportMetrics.

private static void reportMetrics(StatisticsProvider statsProvider) {
    if (statsProvider instanceof MetricStatisticsProvider) {
        MetricRegistry metricRegistry = ((MetricStatisticsProvider) statsProvider).getRegistry();
        ConsoleReporter.forRegistry(metricRegistry).outputTo(System.out).filter(new MetricFilter() {

            @Override
            public boolean matches(String name, Metric metric) {
                if (metric instanceof Counting) {
                    // Only report non zero metrics
                    return ((Counting) metric).getCount() > 0;
                }
                return true;
            }
        }).build().report();
    }
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricStatisticsProvider(org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider) Metric(com.codahale.metrics.Metric) Counting(com.codahale.metrics.Counting)

Example 9 with MetricFilter

use of com.codahale.metrics.MetricFilter in project openscoring by openscoring.

the class ModelResource method undeploy.

@DELETE
@Path("{id:" + ModelRegistry.ID_REGEX + "}")
@RolesAllowed(value = { "admin" })
@Produces(MediaType.APPLICATION_JSON)
public SimpleResponse undeploy(@PathParam("id") String id) {
    Model model = this.modelRegistry.get(id);
    if (model == null) {
        throw new NotFoundException("Model \"" + id + "\" not found");
    }
    boolean success = this.modelRegistry.remove(id, model);
    if (!success) {
        throw new InternalServerErrorException("Concurrent modification");
    }
    final String prefix = createNamePrefix(id);
    MetricFilter filter = new MetricFilter() {

        @Override
        public boolean matches(String name, Metric metric) {
            return name.startsWith(prefix);
        }
    };
    this.metricRegistry.removeMatching(filter);
    SimpleResponse response = new SimpleResponse();
    return response;
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) SimpleResponse(org.openscoring.common.SimpleResponse) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Metric(com.codahale.metrics.Metric) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 10 with MetricFilter

use of com.codahale.metrics.MetricFilter in project killbill by killbill.

the class CacheProviderBase method createCache.

<C extends Configuration> void createCache(final CacheManager cacheManager, final String cacheName, final C configuration) {
    // Make sure we start from a clean state - this is mainly useful for tests
    cacheManager.destroyCache(cacheName);
    final Cache cache = cacheManager.createCache(cacheName, configuration);
    Preconditions.checkState(!cache.isClosed(), "Cache '%s' should not be closed", cacheName);
    // Re-create the metrics to support dynamically created caches (e.g. for Shiro)
    metricRegistry.removeMatching(new MetricFilter() {

        @Override
        public boolean matches(final String name, final Metric metric) {
            return name != null && name.startsWith(PROP_METRIC_REG_JCACHE_STATISTICS);
        }
    });
    metricRegistry.register(PROP_METRIC_REG_JCACHE_STATISTICS, new JCacheGaugeSet());
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Metric(com.codahale.metrics.Metric) JCacheGaugeSet(com.codahale.metrics.jcache.JCacheGaugeSet) Cache(javax.cache.Cache)

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