public class SolrMetricManager extends Object
MetricRegistry
instances, and provides several
helper methods for managing various aspects of metrics reporting:
SolrMetricReporter
-s specific to a named registry.MetricRegistry
instances are automatically created when first referenced by name. Similarly,
instances of Metric
implementations, such as Meter
, Counter
, Timer
and
Histogram
are automatically created and registered under hierarchical names, in a specified
registry, when meter(SolrInfoBean, String, String, String...)
and other similar methods are called.
This class enforces a common prefix (REGISTRY_NAME_PREFIX
) in all registry
names.
Solr uses several different registries for collecting metrics belonging to different groups, using
SolrInfoBean.Group
as the main name of the registry (plus the
above-mentioned prefix). Instances of SolrMetricManager
are created for each CoreContainer
,
and most registries are local to each instance, with the exception of two global registries:
solr.jetty
and solr.jvm
, which are shared between all CoreContainer
-s
Modifier and Type | Class and Description |
---|---|
static class |
SolrMetricManager.AndFilter
An implementation of
MetricFilter that selects metrics
that match all filters in a list of filters. |
static class |
SolrMetricManager.GaugeWrapper<T>
This is a wrapper for
Gauge metrics, which are usually implemented as
lambdas that often keep a reference to their parent instance. |
static class |
SolrMetricManager.OrFilter
An implementation of
MetricFilter that selects metrics
that match any filter in a list of filters. |
static class |
SolrMetricManager.PrefixFilter
An implementation of
MetricFilter that selects metrics
with names that start with one of prefixes. |
static class |
SolrMetricManager.RegexFilter
An implementation of
MetricFilter that selects metrics
with names that match regular expression patterns. |
static class |
SolrMetricManager.ResolutionStrategy
Potential conflict resolution strategies when attempting to register a new metric that already exists
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CLOUD_REPORTER_PERIOD |
static String |
JETTY_REGISTRY
Registry name for Jetty-specific metrics.
|
static String |
JVM_REGISTRY
Registry name for JVM-specific metrics.
|
static String |
REGISTRY_NAME_PREFIX
Common prefix for all registry names that Solr uses.
|
Constructor and Description |
---|
SolrMetricManager() |
SolrMetricManager(SolrResourceLoader loader,
MetricsConfig metricsConfig) |
Modifier and Type | Method and Description |
---|---|
Set<String> |
clearMetrics(String registry,
String... metricPath)
Remove some metrics from a named registry
|
void |
clearRegistry(String registry)
Remove all metrics from a specified registry.
|
boolean |
closeReporter(String registry,
String name,
String tag)
Close and unregister a named
SolrMetricReporter for a registry. |
Set<String> |
closeReporters(String registry)
Close and unregister all
SolrMetricReporter -s for a registry. |
Set<String> |
closeReporters(String registry,
String tag)
Close and unregister all
SolrMetricReporter -s for a registry. |
com.codahale.metrics.Counter |
counter(SolrInfoBean info,
String registry,
String metricName,
String... metricPath)
Create or get an existing named
Counter |
static String |
enforcePrefix(String name)
Enforces the leading
REGISTRY_NAME_PREFIX in a name. |
com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Counter> |
getCounterSupplier() |
com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Histogram> |
getHistogramSupplier() |
com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Meter> |
getMeterSupplier() |
Map<String,com.codahale.metrics.Metric> |
getMetrics(String registry,
com.codahale.metrics.MetricFilter metricFilter)
Retrieve matching metrics and their names.
|
static String |
getRegistryName(SolrInfoBean.Group group,
String... names)
Helper method to construct a properly prefixed registry name based on the group.
|
Map<String,SolrMetricReporter> |
getReporters(String registry)
Get a map of reporters for a registry.
|
com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> |
getTimerSupplier() |
boolean |
hasRegistry(String name)
Check whether a registry with a given name already exists.
|
com.codahale.metrics.Histogram |
histogram(SolrInfoBean info,
String registry,
String metricName,
String... metricPath)
Create or get an existing named
Histogram |
void |
loadClusterReporters(PluginInfo[] pluginInfos,
CoreContainer cc) |
void |
loadReporter(String registry,
CoreContainer coreContainer,
PluginInfo pluginInfo)
Convenience wrapper for
loadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passing CoreContainer.getResourceLoader() and null solrCore and tag. |
void |
loadReporter(String registry,
SolrCore solrCore,
PluginInfo pluginInfo,
String tag)
Convenience wrapper for
loadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passing SolrCore.getResourceLoader() and SolrCore.getCoreContainer() as the extra parameters. |
void |
loadReporter(String registry,
SolrResourceLoader loader,
CoreContainer coreContainer,
SolrCore solrCore,
PluginInfo pluginInfo,
String tag)
Create and register an instance of
SolrMetricReporter . |
void |
loadReporters(PluginInfo[] pluginInfos,
SolrResourceLoader loader,
CoreContainer coreContainer,
SolrCore solrCore,
String tag,
SolrInfoBean.Group group,
String... registryNames)
Create and register
SolrMetricReporter -s specific to a SolrInfoBean.Group . |
void |
loadShardReporters(PluginInfo[] pluginInfos,
SolrCore core) |
static String |
makeName(List<String> path,
String name) |
com.codahale.metrics.Meter |
meter(SolrInfoBean info,
String registry,
String metricName,
String... metricPath)
Create or get an existing named
Meter |
static String |
mkName(String name,
String... path)
This method creates a hierarchical name with arbitrary levels of hierarchy
|
Object |
notANumber()
Return an object used for representing a "Not A Number" (NaN) value.
|
Object |
nullNumber()
Return an object used for representing a null (missing) numeric value.
|
Object |
nullObject()
Return an object used for representing a null (missing) object value.
|
Object |
nullString()
Return an object used for representing a null (missing) string value.
|
void |
registerAll(String registry,
com.codahale.metrics.MetricSet metrics,
SolrMetricManager.ResolutionStrategy strategy,
String... metricPath)
Register all metrics in the provided
MetricSet , optionally skipping those that
already exist. |
void |
registerGauge(SolrInfoBean info,
String registry,
com.codahale.metrics.Gauge<?> gauge,
String tag,
boolean force,
String metricName,
String... metricPath) |
void |
registerMetric(SolrInfoBean info,
String registry,
com.codahale.metrics.Metric metric,
boolean force,
String metricName,
String... metricPath)
Register an instance of
Metric . |
com.codahale.metrics.MetricRegistry |
registry(String registry)
Get (or create if not present) a named registry
|
Set<String> |
registryNames()
Return a set of existing registry names.
|
Set<String> |
registryNames(Pattern... patterns) |
Set<String> |
registryNames(String... patterns)
Return set of existing registry names that match a regex pattern
|
void |
removeRegistry(String registry)
Remove a named registry.
|
void |
swapRegistries(String registry1,
String registry2)
Swap registries.
|
com.codahale.metrics.Timer |
timer(SolrInfoBean info,
String registry,
String metricName,
String... metricPath)
Create or get an existing named
Timer |
int |
unregisterGauges(String registryName,
String tagSegment) |
public static final String REGISTRY_NAME_PREFIX
public static final String JETTY_REGISTRY
SolrMetricManager
.public static final String JVM_REGISTRY
SolrMetricManager
.public static final int DEFAULT_CLOUD_REPORTER_PERIOD
public SolrMetricManager()
public SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig)
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Counter> getCounterSupplier()
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Meter> getMeterSupplier()
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> getTimerSupplier()
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Histogram> getHistogramSupplier()
public Object nullNumber()
public Object notANumber()
public Object nullString()
public Object nullObject()
public boolean hasRegistry(String name)
name
- registry namepublic Set<String> registryNames(String... patterns) throws PatternSyntaxException
patterns
- regex patterns. NOTE: users need to make sure that patterns that
don't start with a wildcard use the full registry name starting with
REGISTRY_NAME_PREFIX
PatternSyntaxException
public com.codahale.metrics.MetricRegistry registry(String registry)
registry
- name of the registrypublic void removeRegistry(String registry)
registry
- name of the registry to removepublic void swapRegistries(String registry1, String registry2)
SolrCore
rename or swap operations. NOTE:
this operation is not supported for shared registries.registry1
- source registryregistry2
- target registry. Note: when used after core rename the target registry doesn't
exist, so the swap operation will only rename the existing registry without creating
an empty one under the previous name.public void registerAll(String registry, com.codahale.metrics.MetricSet metrics, SolrMetricManager.ResolutionStrategy strategy, String... metricPath) throws Exception
MetricSet
, optionally skipping those that
already exist.registry
- registry namemetrics
- metric set to registerstrategy
- the conflict resolution strategy to use if the named metric already exists.metricPath
- (optional) additional top-most metric name path elementsException
- if a metric with this name already exists.public void clearRegistry(String registry)
registry
- registry namepublic Set<String> clearMetrics(String registry, String... metricPath)
registry
- registry namemetricPath
- (optional) top-most metric name path elements. If empty then
this is equivalent to calling clearRegistry(String)
,
otherwise non-empty elements will be joined using dotted notation
to form a fully-qualified prefix. Metrics with names that start
with the prefix will be removed.public Map<String,com.codahale.metrics.Metric> getMetrics(String registry, com.codahale.metrics.MetricFilter metricFilter)
registry
- registry name.metricFilter
- filter (null is equivalent to MetricFilter.ALL
).public com.codahale.metrics.Meter meter(SolrInfoBean info, String registry, String metricName, String... metricPath)
Meter
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name
using dotted notationmetricPath
- (optional) additional top-most metric name path elementsMeter
public com.codahale.metrics.Timer timer(SolrInfoBean info, String registry, String metricName, String... metricPath)
Timer
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name
using dotted notationmetricPath
- (optional) additional top-most metric name path elementsTimer
public com.codahale.metrics.Counter counter(SolrInfoBean info, String registry, String metricName, String... metricPath)
Counter
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name
using dotted notationmetricPath
- (optional) additional top-most metric name path elementsCounter
public com.codahale.metrics.Histogram histogram(SolrInfoBean info, String registry, String metricName, String... metricPath)
Histogram
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name
using dotted notationmetricPath
- (optional) additional top-most metric name path elementsHistogram
public void registerMetric(SolrInfoBean info, String registry, com.codahale.metrics.Metric metric, boolean force, String metricName, String... metricPath)
Metric
.registry
- registry namemetric
- metric instanceforce
- if true then an already existing metric with the same name will be replaced.
When false and a metric with the same name already exists an exception
will be thrown.metricName
- metric name, either final name or a fully-qualified name
using dotted notationmetricPath
- (optional) additional top-most metric name path elementspublic void registerGauge(SolrInfoBean info, String registry, com.codahale.metrics.Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath)
public static String mkName(String name, String... path)
name
- the final segment of the name, must not be null or empty.path
- optional path segments, starting from the top level. Empty or null
segments will be skipped.public static String enforcePrefix(String name)
REGISTRY_NAME_PREFIX
in a name.name
- input name, possibly without the prefixpublic static String getRegistryName(SolrInfoBean.Group group, String... names)
group
- reporting groupnames
- optional child elements of the registry name. If exactly one element is provided
and it already contains the required prefix and group name then this value will be used,
and the group parameter will be ignored.public void loadReporters(PluginInfo[] pluginInfos, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, String tag, SolrInfoBean.Group group, String... registryNames)
SolrMetricReporter
-s specific to a SolrInfoBean.Group
.
Note: reporters that specify neither "group" nor "registry" attributes are treated as universal -
they will always be loaded for any group. These two attributes may also contain multiple comma- or
whitespace-separated values, in which case the reporter will be loaded for any matching value from
the list. If both attributes are present then only "group" attribute will be processed.pluginInfos
- plugin configurationsloader
- resource loadercoreContainer
- core containersolrCore
- optional solr coretag
- optional tag for the reporters, to distinguish reporters logically created for different parent
component instances.group
- selected group, not nullregistryNames
- optional child registry name elementspublic void loadReporter(String registry, SolrCore solrCore, PluginInfo pluginInfo, String tag) throws Exception
loadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passing SolrCore.getResourceLoader()
and SolrCore.getCoreContainer()
as the extra parameters.Exception
public void loadReporter(String registry, CoreContainer coreContainer, PluginInfo pluginInfo) throws Exception
loadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passing CoreContainer.getResourceLoader()
and null solrCore and tag.Exception
public void loadReporter(String registry, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, PluginInfo pluginInfo, String tag) throws Exception
SolrMetricReporter
.registry
- reporter is associated with this registryloader
- loader to use when creating an instance of the reportercoreContainer
- core containersolrCore
- optional solr corepluginInfo
- plugin configuration. Plugin "name" and "class" attributes are required.tag
- optional tag for the reporter, to distinguish reporters logically created for different parent
component instances.Exception
- if any argument is missing or invalidpublic boolean closeReporter(String registry, String name, String tag)
SolrMetricReporter
for a registry.registry
- registry namename
- reporter nametag
- optional tag for the reporter, to distinguish reporters logically created for different parent
component instances.public Set<String> closeReporters(String registry)
SolrMetricReporter
-s for a registry.registry
- registry namepublic Set<String> closeReporters(String registry, String tag)
SolrMetricReporter
-s for a registry.registry
- registry nametag
- optional tag for the reporter, to distinguish reporters logically created for different parent
component instances.public Map<String,SolrMetricReporter> getReporters(String registry)
registry
- registry namepublic void loadShardReporters(PluginInfo[] pluginInfos, SolrCore core)
public void loadClusterReporters(PluginInfo[] pluginInfos, CoreContainer cc)
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.