Class MetricUtils


  • public class MetricUtils
    extends Object
    Metrics specific utility functions.
    • Constructor Detail

      • MetricUtils

        public MetricUtils()
    • Method Detail

      • addMetrics

        public static void addMetrics​(org.apache.solr.common.util.NamedList<Object> lst,
                                      com.codahale.metrics.Timer timer)
        Adds metrics from a Timer to a NamedList, using well-known back-compat names.
        Parameters:
        lst - The NamedList to add the metrics data to
        timer - The Timer to extract the metrics from
      • nsToMs

        public static double nsToMs​(double ns)
        Converts a double representing nanoseconds to a double representing milliseconds.
        Parameters:
        ns - the amount of time in nanoseconds
        Returns:
        the amount of time in milliseconds
      • toSolrInputDocuments

        public static void toSolrInputDocuments​(com.codahale.metrics.MetricRegistry registry,
                                                List<com.codahale.metrics.MetricFilter> shouldMatchFilters,
                                                com.codahale.metrics.MetricFilter mustMatchFilter,
                                                Predicate<CharSequence> propertyFilter,
                                                boolean skipHistograms,
                                                boolean skipAggregateValues,
                                                boolean compact,
                                                Map<String,​Object> metadata,
                                                Consumer<org.apache.solr.common.SolrInputDocument> consumer)
        Provides a representation of the given metric registry as SolrInputDocument-s. Only those metrics are converted which match at least one of the given MetricFilter instances.
        Parameters:
        registry - the MetricRegistry to be converted
        shouldMatchFilters - a list of MetricFilter instances. A metric must match any one of the filters from this list to be included in the output
        mustMatchFilter - a MetricFilter. A metric must match this filter to be included in the output.
        propertyFilter - limit what properties of a metric are returned
        skipHistograms - discard any Histogram-s and histogram parts of Timer-s.
        skipAggregateValues - discard internal values of AggregateMetric-s.
        compact - use compact representation for counters and gauges.
        metadata - optional metadata. If not null and not empty then this map will be added under a _metadata_ key.
        consumer - consumer that accepts produced SolrInputDocument-s
      • toMaps

        public static void toMaps​(com.codahale.metrics.MetricRegistry registry,
                                  List<com.codahale.metrics.MetricFilter> shouldMatchFilters,
                                  com.codahale.metrics.MetricFilter mustMatchFilter,
                                  Predicate<CharSequence> propertyFilter,
                                  boolean skipHistograms,
                                  boolean skipAggregateValues,
                                  boolean compact,
                                  boolean simple,
                                  BiConsumer<String,​Object> consumer)
        Convert selected metrics to maps or to flattened objects.
        Parameters:
        registry - source of metrics
        shouldMatchFilters - metrics must match any of these filters
        mustMatchFilter - metrics must match this filter
        propertyFilter - limit what properties of a metric are returned
        skipHistograms - discard any Histogram-s and histogram parts of Timer-s.
        skipAggregateValues - discard internal values of AggregateMetric-s.
        compact - use compact representation for counters and gauges.
        simple - use simplified representation for complex metrics - instead of a (name, map) only the selected (name "." key, value) pairs will be produced.
        consumer - consumer that accepts produced objects
      • convertMetrics

        public static Map<String,​Object> convertMetrics​(com.codahale.metrics.MetricRegistry registry,
                                                              Collection<String> names)
        Convert selected metrics from a registry into a map, with metrics in a compact AND simple format.
        Parameters:
        registry - registry
        names - metric names
        Returns:
        map where keys are metric names (if they were present in the registry) and values are converted metrics in simplified format.
      • convertMetrics

        public static void convertMetrics​(com.codahale.metrics.MetricRegistry registry,
                                          Collection<String> names,
                                          boolean skipHistograms,
                                          boolean skipAggregateValues,
                                          boolean compact,
                                          boolean simple,
                                          BiConsumer<String,​Object> consumer)
        Convert selected metrics from a registry into maps (when compact==false) or flattened objects.
        Parameters:
        registry - registry
        names - metric names
        skipHistograms - discard any Histogram-s and histogram parts of Timer-s.
        skipAggregateValues - discard internal values of AggregateMetric-s.
        compact - use compact representation for counters and gauges.
        simple - use simplified representation for complex metrics - instead of a (name, map) only the selected (name "." key, value) pairs will be produced.
        consumer - consumer that accepts produced objects
      • convertMetric

        public static void convertMetric​(String n,
                                         com.codahale.metrics.Metric metric,
                                         Predicate<CharSequence> propertyFilter,
                                         boolean skipHistograms,
                                         boolean skipAggregateValues,
                                         boolean compact,
                                         boolean simple,
                                         String separator,
                                         BiConsumer<String,​Object> consumer)
        Convert a single instance of metric into a map or flattened object.
        Parameters:
        n - metric name
        metric - metric instance
        propertyFilter - limit what properties of a metric are returned
        skipHistograms - discard any Histogram-s and histogram parts of Timer-s.
        skipAggregateValues - discard internal values of AggregateMetric-s.
        compact - use compact representation for counters and gauges.
        simple - use simplified representation for complex metrics - instead of a (name, map) only the selected (name "." key, value) pairs will be produced.
        consumer - consumer that accepts produced objects
      • convertTimer

        public static void convertTimer​(String name,
                                        com.codahale.metrics.Timer timer,
                                        Predicate<CharSequence> propertyFilter,
                                        boolean skipHistograms,
                                        boolean simple,
                                        String separator,
                                        BiConsumer<String,​Object> consumer)
        Convert a Timer to a map.
        Parameters:
        name - metric name
        timer - timer instance
        propertyFilter - limit what properties of a metric are returned
        skipHistograms - if true then discard the histogram part of the timer.
        simple - use simplified representation for complex metrics - instead of a (name, map) only the selected (name "." key, value) pairs will be produced.
        consumer - consumer that accepts produced objects
      • instrumentedExecutorService

        public static ExecutorService instrumentedExecutorService​(ExecutorService delegate,
                                                                  SolrInfoBean info,
                                                                  com.codahale.metrics.MetricRegistry metricRegistry,
                                                                  String scope)
        Returns an instrumented wrapper over the given executor service.
      • addMXBeanMetrics

        public static <T extends PlatformManagedObject> void addMXBeanMetrics​(T obj,
                                                                              Class<? extends T> intf,
                                                                              String prefix,
                                                                              BiConsumer<String,​com.codahale.metrics.Metric> consumer)
        Creates a set of metrics (gauges) that correspond to available bean properties for the provided MXBean.
        Type Parameters:
        T - formal type
        Parameters:
        obj - an instance of MXBean
        intf - MXBean interface, one of PlatformManagedObject-s
        consumer - consumer for created names and metrics
      • addMXBeanMetrics

        public static <T extends PlatformManagedObject> void addMXBeanMetrics​(T obj,
                                                                              String[] interfaces,
                                                                              String prefix,
                                                                              BiConsumer<String,​com.codahale.metrics.Metric> consumer)
        Creates a set of metrics (gauges) that correspond to available bean properties for the provided MXBean.
        Type Parameters:
        T - formal type
        Parameters:
        obj - an instance of MXBean
        interfaces - interfaces that it may implement. Each interface will be tried in turn, and only if it exists and if it contains unique properties then they will be added as metrics.
        prefix - optional prefix for metric names
        consumer - consumer for created names and metrics