public class MetricUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
MetricUtils.PropertyFilter
This filter can limit what properties of a metric are returned.
|
Modifier and Type | Field and Description |
---|---|
static String |
METRIC_NAME |
static String[] |
OS_MXBEAN_CLASSES
These are well-known implementations of
OperatingSystemMXBean . |
static String |
VALUE |
static String |
VALUES |
Constructor and Description |
---|
MetricUtils() |
Modifier and Type | Method and 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> |
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.
|
static <T extends PlatformManagedObject> |
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.
|
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 (when
compact==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 a
Timer 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 as
SolrInputDocument -s. |
public static final String METRIC_NAME
public static final String VALUE
public static final String VALUES
public static String[] OS_MXBEAN_CLASSES
OperatingSystemMXBean
.
Some of them provide additional useful properties beyond those declared by the interface.public static void addMetrics(NamedList<Object> lst, com.codahale.metrics.Timer timer)
lst
- The NamedList to add the metrics data totimer
- The Timer to extract the metrics frompublic static double nsToMs(double ns)
ns
- the amount of time in nanosecondspublic 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)
SolrInputDocument
-s.
Only those metrics
are converted which match at least one of the given MetricFilter instances.registry
- the MetricRegistry
to be convertedshouldMatchFilters
- a list of MetricFilter
instances.
A metric must match any one of the filters from this list to be
included in the outputmustMatchFilter
- a MetricFilter
.
A metric must match this filter to be included in the output.propertyFilter
- limit what properties of a metric are returnedskipHistograms
- 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
-spublic 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)
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 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 objectspublic static Map<String,Object> convertMetrics(com.codahale.metrics.MetricRegistry registry, Collection<String> names)
registry
- registrynames
- metric namespublic static void convertMetrics(com.codahale.metrics.MetricRegistry registry, Collection<String> names, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String,Object> consumer)
compact==false
) or
flattened objects.registry
- registrynames
- metric namesskipHistograms
- 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 objectspublic 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)
n
- metric namemetric
- metric instancepropertyFilter
- limit what properties of a metric are returnedskipHistograms
- 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 objectspublic static void convertTimer(String name, com.codahale.metrics.Timer timer, MetricUtils.PropertyFilter propertyFilter, boolean skipHistograms, boolean simple, String separator, BiConsumer<String,Object> consumer)
Timer
to a map.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 objectspublic static ExecutorService instrumentedExecutorService(ExecutorService delegate, SolrInfoBean info, com.codahale.metrics.MetricRegistry metricRegistry, String scope)
public static <T extends PlatformManagedObject> void addMXBeanMetrics(T obj, Class<? extends T> intf, String prefix, BiConsumer<String,com.codahale.metrics.Metric> consumer)
T
- formal typeobj
- an instance of MXBeanintf
- MXBean interface, one of PlatformManagedObject
-sconsumer
- consumer for created names and metricspublic static <T extends PlatformManagedObject> void addMXBeanMetrics(T obj, String[] interfaces, String prefix, BiConsumer<String,com.codahale.metrics.Metric> consumer)
T
- formal typeobj
- 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 metricsCopyright © 2000-2019 Apache Software Foundation. All Rights Reserved.