Package org.apache.solr.metrics
Class SolrMetricManager
- java.lang.Object
-
- org.apache.solr.metrics.SolrMetricManager
-
public class SolrMetricManager extends Object
This class maintains a repository of namedMetricRegistry
instances, and provides several helper methods for managing various aspects of metrics reporting:- registry creation, clearing and removal,
- creation of most common metric implementations,
- management of
SolrMetricReporter
-s specific to a named registry.
MetricRegistry
instances are automatically created when first referenced by name. Similarly, instances ofMetric
implementations, such asMeter
,Counter
,Timer
andHistogram
are automatically created and registered under hierarchical names, in a specified registry, whenmeter(SolrMetricsContext, 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 ofSolrMetricManager
are created for eachCoreContainer
, and most registries are local to each instance, with the exception of two global registries:solr.jetty
andsolr.jvm
, which are shared between allCoreContainer
-s
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SolrMetricManager.AndFilter
An implementation ofMetricFilter
that selects metrics that match all filters in a list of filters.static class
SolrMetricManager.GaugeWrapper<T>
This is a wrapper forGauge
metrics, which are usually implemented as lambdas that often keep a reference to their parent instance.static class
SolrMetricManager.OrFilter
An implementation ofMetricFilter
that selects metrics that match any filter in a list of filters.static class
SolrMetricManager.PrefixFilter
An implementation ofMetricFilter
that selects metrics with names that start with one of prefixes.static class
SolrMetricManager.RegexFilter
An implementation ofMetricFilter
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
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description SolrMetricManager()
SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Set<String>
clearMetrics(String registry, String... metricPath)
Remove some metrics from a named registryvoid
clearRegistry(String registry)
Remove all metrics from a specified registry.boolean
closeReporter(String registry, String name, String tag)
Close and unregister a namedSolrMetricReporter
for a registry.Set<String>
closeReporters(String registry)
Close and unregister allSolrMetricReporter
-s for a registry.Set<String>
closeReporters(String registry, String tag)
Close and unregister allSolrMetricReporter
-s for a registry.com.codahale.metrics.Counter
counter(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedCounter
static String
enforcePrefix(String name)
Enforces the leadingREGISTRY_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.MetricsConfig
getMetricsConfig()
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(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedHistogram
void
loadClusterReporters(PluginInfo[] pluginInfos, CoreContainer cc)
void
loadReporter(String registry, CoreContainer coreContainer, PluginInfo pluginInfo)
Convenience wrapper forloadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passingCoreContainer.getResourceLoader()
and null solrCore and tag.void
loadReporter(String registry, SolrCore solrCore, PluginInfo pluginInfo, String tag)
Convenience wrapper forloadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passingSolrCore.getResourceLoader()
andSolrCore.getCoreContainer()
as the extra parameters.void
loadReporter(String registry, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, PluginInfo pluginInfo, String tag)
Create and register an instance ofSolrMetricReporter
.void
loadReporters(PluginInfo[] pluginInfos, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, String tag, SolrInfoBean.Group group, String... registryNames)
Create and registerSolrMetricReporter
-s specific to aSolrInfoBean.Group
.void
loadShardReporters(PluginInfo[] pluginInfos, SolrCore core)
static String
makeName(List<String> path, String name)
com.codahale.metrics.Meter
meter(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedMeter
static String
mkName(String name, String... path)
This method creates a hierarchical name with arbitrary levels of hierarchyObject
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 providedMetricSet
, optionally skipping those that already exist.void
registerGauge(SolrMetricsContext context, String registry, com.codahale.metrics.Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath)
<T> void
registerGauge(SolrMetricsContext context, String registry, com.codahale.metrics.Gauge<T> gauge, String tag, SolrMetricManager.ResolutionStrategy strategy, String metricName, String... metricPath)
void
registerMetric(SolrMetricsContext context, String registry, com.codahale.metrics.Metric metric, boolean force, String metricName, String... metricPath)
void
registerMetric(SolrMetricsContext context, String registry, com.codahale.metrics.Metric metric, SolrMetricManager.ResolutionStrategy strategy, String metricName, String... metricPath)
Register an instance ofMetric
.com.codahale.metrics.MetricRegistry
registry(String registry)
Get (or create if not present) a named registrySet<String>
registryNames()
Return a set of existing registry names.Set<String>
registryNames(String... patterns)
Return set of existing registry names that match a regex patternSet<String>
registryNames(Pattern... patterns)
void
removeRegistry(String registry)
Remove a named registry.void
swapRegistries(String registry1, String registry2)
Swap registries.com.codahale.metrics.Timer
timer(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedTimer
int
unregisterGauges(String registryName, String tagSegment)
-
-
-
Field Detail
-
REGISTRY_NAME_PREFIX
public static final String REGISTRY_NAME_PREFIX
Common prefix for all registry names that Solr uses.- See Also:
- Constant Field Values
-
JETTY_REGISTRY
public static final String JETTY_REGISTRY
Registry name for Jetty-specific metrics. This name is also subject to overrides controlled by system properties. This registry is shared between instances ofSolrMetricManager
.
-
JVM_REGISTRY
public static final String JVM_REGISTRY
Registry name for JVM-specific metrics. This name is also subject to overrides controlled by system properties. This registry is shared between instances ofSolrMetricManager
.
-
DEFAULT_CLOUD_REPORTER_PERIOD
public static final int DEFAULT_CLOUD_REPORTER_PERIOD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SolrMetricManager
public SolrMetricManager()
-
SolrMetricManager
public SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig)
-
-
Method Detail
-
getCounterSupplier
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Counter> getCounterSupplier()
-
getMeterSupplier
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Meter> getMeterSupplier()
-
getTimerSupplier
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> getTimerSupplier()
-
getHistogramSupplier
public com.codahale.metrics.MetricRegistry.MetricSupplier<com.codahale.metrics.Histogram> getHistogramSupplier()
-
nullNumber
public Object nullNumber()
Return an object used for representing a null (missing) numeric value.
-
notANumber
public Object notANumber()
Return an object used for representing a "Not A Number" (NaN) value.
-
nullString
public Object nullString()
Return an object used for representing a null (missing) string value.
-
nullObject
public Object nullObject()
Return an object used for representing a null (missing) object value.
-
hasRegistry
public boolean hasRegistry(String name)
Check whether a registry with a given name already exists.- Parameters:
name
- registry name- Returns:
- true if this name points to a registry that already exists, false otherwise
-
registryNames
public Set<String> registryNames(String... patterns) throws PatternSyntaxException
Return set of existing registry names that match a regex pattern- Parameters:
patterns
- regex patterns. NOTE: users need to make sure that patterns that don't start with a wildcard use the full registry name starting withREGISTRY_NAME_PREFIX
- Returns:
- set of existing registry names where at least one pattern matched.
- Throws:
PatternSyntaxException
-
registry
public com.codahale.metrics.MetricRegistry registry(String registry)
Get (or create if not present) a named registry- Parameters:
registry
- name of the registry- Returns:
- existing or newly created registry
-
removeRegistry
public void removeRegistry(String registry)
Remove a named registry.- Parameters:
registry
- name of the registry to remove
-
swapRegistries
public void swapRegistries(String registry1, String registry2)
Swap registries. This is useful eg. duringSolrCore
rename or swap operations. NOTE: this operation is not supported for shared registries.- Parameters:
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.
-
registerAll
public void registerAll(String registry, com.codahale.metrics.MetricSet metrics, SolrMetricManager.ResolutionStrategy strategy, String... metricPath) throws Exception
Register all metrics in the providedMetricSet
, optionally skipping those that already exist.- Parameters:
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 elements- Throws:
Exception
- if a metric with this name already exists.
-
clearRegistry
public void clearRegistry(String registry)
Remove all metrics from a specified registry.- Parameters:
registry
- registry name
-
clearMetrics
public Set<String> clearMetrics(String registry, String... metricPath)
Remove some metrics from a named registry- Parameters:
registry
- registry namemetricPath
- (optional) top-most metric name path elements. If empty then this is equivalent to callingclearRegistry(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.- Returns:
- set of metrics names that have been removed.
-
getMetrics
public Map<String,com.codahale.metrics.Metric> getMetrics(String registry, com.codahale.metrics.MetricFilter metricFilter)
Retrieve matching metrics and their names.- Parameters:
registry
- registry name.metricFilter
- filter (null is equivalent toMetricFilter.ALL
).- Returns:
- map of matching names and metrics
-
meter
public com.codahale.metrics.Meter meter(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedMeter
- Parameters:
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name using dotted notationmetricPath
- (optional) additional top-most metric name path elements- Returns:
- existing or a newly created
Meter
-
timer
public com.codahale.metrics.Timer timer(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedTimer
- Parameters:
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name using dotted notationmetricPath
- (optional) additional top-most metric name path elements- Returns:
- existing or a newly created
Timer
-
counter
public com.codahale.metrics.Counter counter(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedCounter
- Parameters:
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name using dotted notationmetricPath
- (optional) additional top-most metric name path elements- Returns:
- existing or a newly created
Counter
-
histogram
public com.codahale.metrics.Histogram histogram(SolrMetricsContext context, String registry, String metricName, String... metricPath)
Create or get an existing namedHistogram
- Parameters:
registry
- registry namemetricName
- metric name, either final name or a fully-qualified name using dotted notationmetricPath
- (optional) additional top-most metric name path elements- Returns:
- existing or a newly created
Histogram
-
registerMetric
@Deprecated public void registerMetric(SolrMetricsContext context, String registry, com.codahale.metrics.Metric metric, boolean force, String metricName, String... metricPath)
-
registerMetric
public void registerMetric(SolrMetricsContext context, String registry, com.codahale.metrics.Metric metric, SolrMetricManager.ResolutionStrategy strategy, String metricName, String... metricPath)
Register an instance ofMetric
.- Parameters:
registry
- registry namemetric
- metric instancestrategy
- the conflict resolution strategy to use if the named metric already exists.metricName
- metric name, either final name or a fully-qualified name using dotted notationmetricPath
- (optional) additional top-most metric name path elements
-
registerGauge
@Deprecated public void registerGauge(SolrMetricsContext context, String registry, com.codahale.metrics.Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath)
-
registerGauge
public <T> void registerGauge(SolrMetricsContext context, String registry, com.codahale.metrics.Gauge<T> gauge, String tag, SolrMetricManager.ResolutionStrategy strategy, String metricName, String... metricPath)
-
mkName
public static String mkName(String name, String... path)
This method creates a hierarchical name with arbitrary levels of hierarchy- Parameters:
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.- Returns:
- fully-qualified name using dotted notation, with all valid hierarchy segments prepended to the name.
-
enforcePrefix
public static String enforcePrefix(String name)
Enforces the leadingREGISTRY_NAME_PREFIX
in a name.- Parameters:
name
- input name, possibly without the prefix- Returns:
- original name if it contained the prefix, or the input name with the prefix prepended.
-
getRegistryName
public static String getRegistryName(SolrInfoBean.Group group, String... names)
Helper method to construct a properly prefixed registry name based on the group.- Parameters:
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.- Returns:
- fully-qualified and prefixed registry name, with overrides applied.
-
loadReporters
public void loadReporters(PluginInfo[] pluginInfos, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, String tag, SolrInfoBean.Group group, String... registryNames)
Create and registerSolrMetricReporter
-s specific to aSolrInfoBean.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.- Parameters:
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 elements
-
loadReporter
public void loadReporter(String registry, SolrCore solrCore, PluginInfo pluginInfo, String tag) throws Exception
Convenience wrapper forloadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passingSolrCore.getResourceLoader()
andSolrCore.getCoreContainer()
as the extra parameters.- Throws:
Exception
-
loadReporter
public void loadReporter(String registry, CoreContainer coreContainer, PluginInfo pluginInfo) throws Exception
Convenience wrapper forloadReporter(String, SolrResourceLoader, CoreContainer, SolrCore, PluginInfo, String)
passingCoreContainer.getResourceLoader()
and null solrCore and tag.- Throws:
Exception
-
loadReporter
public void loadReporter(String registry, SolrResourceLoader loader, CoreContainer coreContainer, SolrCore solrCore, PluginInfo pluginInfo, String tag) throws Exception
Create and register an instance ofSolrMetricReporter
.- Parameters:
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.- Throws:
Exception
- if any argument is missing or invalid
-
closeReporter
public boolean closeReporter(String registry, String name, String tag)
Close and unregister a namedSolrMetricReporter
for a registry.- Parameters:
registry
- registry namename
- reporter nametag
- optional tag for the reporter, to distinguish reporters logically created for different parent component instances.- Returns:
- true if a named reporter existed and was closed.
-
closeReporters
public Set<String> closeReporters(String registry)
Close and unregister allSolrMetricReporter
-s for a registry.- Parameters:
registry
- registry name- Returns:
- names of closed reporters
-
closeReporters
public Set<String> closeReporters(String registry, String tag)
Close and unregister allSolrMetricReporter
-s for a registry.- Parameters:
registry
- registry nametag
- optional tag for the reporter, to distinguish reporters logically created for different parent component instances.- Returns:
- names of closed reporters
-
getReporters
public Map<String,SolrMetricReporter> getReporters(String registry)
Get a map of reporters for a registry. Keys are reporter names, values are reporter instances.- Parameters:
registry
- registry name- Returns:
- map of reporters and their names, may be empty but never null
-
loadShardReporters
public void loadShardReporters(PluginInfo[] pluginInfos, SolrCore core)
-
loadClusterReporters
public void loadClusterReporters(PluginInfo[] pluginInfos, CoreContainer cc)
-
getMetricsConfig
public MetricsConfig getMetricsConfig()
-
-