Class AbstractMetricGroup<A extends AbstractMetricGroup<?>>
- Type Parameters:
A- The type of the parent MetricGroup
- All Implemented Interfaces:
org.apache.flink.metrics.MetricGroup
- Direct Known Subclasses:
ComponentMetricGroup,GenericMetricGroup,ProcessMetricGroup,ResourceManagerMetricGroup,SlotManagerMetricGroup
MetricGroup that contains key functionality for adding metrics and groups.
IMPORTANT IMPLEMENTATION NOTE
This class uses locks for adding and removing metrics objects. This is done to prevent resource leaks in the presence of concurrently closing a group and adding metrics and subgroups. Since closing groups recursively closes the subgroups, the lock acquisition order must be strictly from parent group to subgroup. If at any point, a subgroup holds its group lock and calls a parent method that also acquires the lock, it will create a deadlock condition.
An AbstractMetricGroup can be closed. Upon closing, the group de-register all
metrics from any metrics reporter and any internal maps. Note that even closed metrics groups
return Counters, Gauges, etc to the code, to prevent exceptions in the monitored code. These
metrics simply do not get reported any more, when created on a closed group.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumEnum for indicating which child group should be created. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Loggerprotected final AThe parent group containing this group.protected QueryScopeInfoThe metrics query service scope represented by this group, lazily computed.protected final MetricRegistryThe registry that this metrics group belongs to.The map containing all variables and their associated values, lazily computed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.metrics.MetricGrouporg.apache.flink.metrics.MetricGroupprotected voidAdds the given metric to the group and registers it at the registry, if the group is not yet closed, and if no metric with the same name has been registered before.voidaddSpan(org.apache.flink.traces.SpanBuilder spanBuilder) voidclose()org.apache.flink.metrics.Counter<C extends org.apache.flink.metrics.Counter>
Cprotected GenericMetricGroupcreateChildGroup(String name, AbstractMetricGroup.ChildType childType) protected StringcreateLogicalScope(org.apache.flink.metrics.CharacterFilter filter, char delimiter) protected abstract QueryScopeInfocreateQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter) Creates the metric query service scope for this group.<T,G extends org.apache.flink.metrics.Gauge<T>>
GgetAllVariables(int reporterIndex, Set<String> excludedVariables) protected abstract StringgetGroupName(org.apache.flink.metrics.CharacterFilter filter) Returns the name for this group, meaning what kind of entity it represents, for example "taskmanager".getLogicalScope(org.apache.flink.metrics.CharacterFilter filter) Returns the logical scope of this group, for example"taskmanager.job.task".getLogicalScope(org.apache.flink.metrics.CharacterFilter filter, char delimiter) Returns the logical scope of this group, for example"taskmanager.job.task".getMetricIdentifier(String metricName) Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter) Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter, int reporterIndex, char delimiter) Returns the fully qualified metric name using the configured delimiter for the reporter with the given index, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".getQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter) Returns the metric query service scope for this group.String[]Gets the scope as an array of the scope components, for example["host-7", "taskmanager-2", "window_word_count", "my-mapper"].<H extends org.apache.flink.metrics.Histogram>
Hfinal booleanisClosed()<M extends org.apache.flink.metrics.Meter>
Mprotected voidputVariables(Map<String, String> variables) Enters all variables specific to thisAbstractMetricGroupand their associated values into the map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.metrics.MetricGroup
addGroup, counter, counter, gauge, histogram, meter
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
parent
The parent group containing this group. -
variables
The map containing all variables and their associated values, lazily computed. -
registry
The registry that this metrics group belongs to. -
queryServiceScopeInfo
The metrics query service scope represented by this group, lazily computed.
-
-
Constructor Details
-
AbstractMetricGroup
-
-
Method Details
-
getAllVariables
- Specified by:
getAllVariablesin interfaceorg.apache.flink.metrics.MetricGroup
-
getAllVariables
-
putVariables
Enters all variables specific to thisAbstractMetricGroupand their associated values into the map.- Parameters:
variables- map to enter variables and their values into
-
getLogicalScope
Returns the logical scope of this group, for example"taskmanager.job.task".- Parameters:
filter- character filter which is applied to the scope components- Returns:
- logical scope
-
getLogicalScope
Returns the logical scope of this group, for example"taskmanager.job.task".- Parameters:
filter- character filter which is applied to the scope components- Returns:
- logical scope
-
createLogicalScope
protected String createLogicalScope(org.apache.flink.metrics.CharacterFilter filter, char delimiter) -
getGroupName
Returns the name for this group, meaning what kind of entity it represents, for example "taskmanager".- Parameters:
filter- character filter which is applied to the name- Returns:
- logical name for this group
-
getScopeComponents
Gets the scope as an array of the scope components, for example["host-7", "taskmanager-2", "window_word_count", "my-mapper"].- Specified by:
getScopeComponentsin interfaceorg.apache.flink.metrics.MetricGroup- See Also:
-
getQueryServiceMetricInfo
Returns the metric query service scope for this group.- Parameters:
filter- character filter- Returns:
- query service scope
-
createQueryServiceMetricInfo
protected abstract QueryScopeInfo createQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter) Creates the metric query service scope for this group.- Parameters:
filter- character filter- Returns:
- query service scope
-
getMetricIdentifier
Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".- Specified by:
getMetricIdentifierin interfaceorg.apache.flink.metrics.MetricGroup- Parameters:
metricName- metric name- Returns:
- fully qualified metric name
-
getMetricIdentifier
public String getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter) Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".- Specified by:
getMetricIdentifierin interfaceorg.apache.flink.metrics.MetricGroup- Parameters:
metricName- metric namefilter- character filter which is applied to the scope components if not null.- Returns:
- fully qualified metric name
-
getMetricIdentifier
public String getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter, int reporterIndex, char delimiter) Returns the fully qualified metric name using the configured delimiter for the reporter with the given index, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName".- Parameters:
metricName- metric namefilter- character filter which is applied to the scope components if not null.reporterIndex- index of the reporter whose delimiter should be useddelimiter- delimiter to use- Returns:
- fully qualified metric name
-
close
public void close() -
isClosed
public final boolean isClosed() -
addSpan
public void addSpan(org.apache.flink.traces.SpanBuilder spanBuilder) - Specified by:
addSpanin interfaceorg.apache.flink.metrics.MetricGroup
-
counter
- Specified by:
counterin interfaceorg.apache.flink.metrics.MetricGroup
-
counter
- Specified by:
counterin interfaceorg.apache.flink.metrics.MetricGroup
-
gauge
- Specified by:
gaugein interfaceorg.apache.flink.metrics.MetricGroup
-
histogram
- Specified by:
histogramin interfaceorg.apache.flink.metrics.MetricGroup
-
meter
- Specified by:
meterin interfaceorg.apache.flink.metrics.MetricGroup
-
addMetric
Adds the given metric to the group and registers it at the registry, if the group is not yet closed, and if no metric with the same name has been registered before.- Parameters:
name- the name to register the metric undermetric- the metric to register
-
addGroup
- Specified by:
addGroupin interfaceorg.apache.flink.metrics.MetricGroup
-
addGroup
- Specified by:
addGroupin interfaceorg.apache.flink.metrics.MetricGroup
-
createChildGroup
-