Package org.apache.solr.util.stats
Class MetricUtils
- java.lang.Object
-
- org.apache.solr.util.stats.MetricUtils
-
public class MetricUtils extends Object
Metrics specific utility functions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MetricUtils.PropertyFilter
This filter can limit what properties of a metric are returned.
-
Field Summary
Fields Modifier and Type Field Description static String
METRIC_NAME
static String[]
OS_MXBEAN_CLASSES
These are well-known implementations ofOperatingSystemMXBean
.static String
VALUE
static String
VALUES
-
Constructor Summary
Constructors Constructor Description MetricUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addMetrics(NamedList<Object> lst, com.codahale.metrics.Timer timer)
Adds metrics from a Timer to a NamedList, using well-known back-compat names.static <T extends PlatformManagedObject>
voidaddMXBeanMetrics(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.static <T extends PlatformManagedObject>
voidaddMXBeanMetrics(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.static void
convertMetric(String n, com.codahale.metrics.Metric metric, MetricUtils.PropertyFilter 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.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.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 (whencompact==false
) or flattened objects.static void
convertTimer(String name, com.codahale.metrics.Timer timer, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean simple, String separator, BiConsumer<String,Object> consumer)
Convert aTimer
to a map.static ExecutorService
instrumentedExecutorService(ExecutorService delegate, SolrInfoBean info, com.codahale.metrics.MetricRegistry metricRegistry, String scope)
Returns an instrumented wrapper over the given executor service.static double
nsToMs(double ns)
Converts a double representing nanoseconds to a double representing milliseconds.static void
toMaps(com.codahale.metrics.MetricRegistry registry, List<com.codahale.metrics.MetricFilter> shouldMatchFilters, com.codahale.metrics.MetricFilter mustMatchFilter, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String,Object> consumer)
Convert selected metrics to maps or to flattened objects.static void
toSolrInputDocuments(com.codahale.metrics.MetricRegistry registry, List<com.codahale.metrics.MetricFilter> shouldMatchFilters, com.codahale.metrics.MetricFilter mustMatchFilter, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, Map<String,Object> metadata, Consumer<SolrInputDocument> consumer)
Provides a representation of the given metric registry asSolrInputDocument
-s.
-
-
-
Field Detail
-
METRIC_NAME
public static final String METRIC_NAME
- See Also:
- Constant Field Values
-
VALUE
public static final String VALUE
- See Also:
- Constant Field Values
-
VALUES
public static final String VALUES
- See Also:
- Constant Field Values
-
OS_MXBEAN_CLASSES
public static String[] OS_MXBEAN_CLASSES
These are well-known implementations ofOperatingSystemMXBean
. Some of them provide additional useful properties beyond those declared by the interface.
-
-
Method Detail
-
addMetrics
public static void addMetrics(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 totimer
- 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, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, Map<String,Object> metadata, Consumer<SolrInputDocument> consumer)
Provides a representation of the given metric registry asSolrInputDocument
-s. Only those metrics are converted which match at least one of the given MetricFilter instances.- Parameters:
registry
- theMetricRegistry
to be convertedshouldMatchFilters
- a list ofMetricFilter
instances. A metric must match any one of the filters from this list to be included in the outputmustMatchFilter
- aMetricFilter
. A metric must match this filter to be included in the output.propertyFilter
- limit what properties of a metric are returnedskipHistograms
- discard anyHistogram
-s and histogram parts ofTimer
-s.skipAggregateValues
- discard internal values ofAggregateMetric
-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 producedSolrInputDocument
-s
-
toMaps
public static void toMaps(com.codahale.metrics.MetricRegistry registry, List<com.codahale.metrics.MetricFilter> shouldMatchFilters, com.codahale.metrics.MetricFilter mustMatchFilter, MetricUtils.PropertyFilter 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 metricsshouldMatchFilters
- metrics must match any of these filtersmustMatchFilter
- metrics must match this filterpropertyFilter
- limit what properties of a metric are returnedskipHistograms
- discard anyHistogram
-s and histogram parts ofTimer
-s.skipAggregateValues
- discard internal values ofAggregateMetric
-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
- registrynames
- 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 (whencompact==false
) or flattened objects.- Parameters:
registry
- registrynames
- metric namesskipHistograms
- discard anyHistogram
-s and histogram parts ofTimer
-s.skipAggregateValues
- discard internal values ofAggregateMetric
-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, MetricUtils.PropertyFilter 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 namemetric
- metric instancepropertyFilter
- limit what properties of a metric are returnedskipHistograms
- discard anyHistogram
-s and histogram parts ofTimer
-s.skipAggregateValues
- discard internal values ofAggregateMetric
-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, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean simple, String separator, BiConsumer<String,Object> consumer)
Convert aTimer
to a map.- Parameters:
name
- metric nametimer
- timer instancepropertyFilter
- limit what properties of a metric are returnedskipHistograms
- 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 MXBeanintf
- MXBean interface, one ofPlatformManagedObject
-sconsumer
- 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 MXBeaninterfaces
- 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 namesconsumer
- consumer for created names and metrics
-
-