A - The type of the parent MetricGroup@Internal public abstract class AbstractMetricGroup<A extends AbstractMetricGroup<?>> extends Object implements org.apache.flink.metrics.MetricGroup
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.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractMetricGroup.ChildType
Enum for indicating which child group should be created.
|
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
LOG |
protected A |
parent
The parent group containing this group.
|
protected QueryScopeInfo |
queryServiceScopeInfo
The metrics query service scope represented by this group, lazily computed.
|
protected MetricRegistry |
registry
The registry that this metrics group belongs to.
|
protected Map<String,String>[] |
variables
The map containing all variables and their associated values, lazily computed.
|
| Constructor and Description |
|---|
AbstractMetricGroup(MetricRegistry registry,
String[] scope,
A parent) |
| Modifier and Type | Method and Description |
|---|---|
org.apache.flink.metrics.MetricGroup |
addGroup(String name) |
org.apache.flink.metrics.MetricGroup |
addGroup(String key,
String value) |
protected void |
addMetric(String name,
org.apache.flink.metrics.Metric metric)
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.
|
void |
addSpan(org.apache.flink.traces.SpanBuilder spanBuilder) |
void |
close() |
org.apache.flink.metrics.Counter |
counter(String name) |
<C extends org.apache.flink.metrics.Counter> |
counter(String name,
C counter) |
protected GenericMetricGroup |
createChildGroup(String name,
AbstractMetricGroup.ChildType childType) |
protected String |
createLogicalScope(org.apache.flink.metrics.CharacterFilter filter,
char delimiter) |
protected abstract QueryScopeInfo |
createQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter)
Creates the metric query service scope for this group.
|
<T,G extends org.apache.flink.metrics.Gauge<T>> |
gauge(String name,
G gauge) |
Map<String,String> |
getAllVariables() |
Map<String,String> |
getAllVariables(int reporterIndex,
Set<String> excludedVariables) |
protected abstract String |
getGroupName(org.apache.flink.metrics.CharacterFilter filter)
Returns the name for this group, meaning what kind of entity it represents, for example
"taskmanager".
|
String |
getLogicalScope(org.apache.flink.metrics.CharacterFilter filter)
Returns the logical scope of this group, for example
"taskmanager.job.task". |
String |
getLogicalScope(org.apache.flink.metrics.CharacterFilter filter,
char delimiter)
Returns the logical scope of this group, for example
"taskmanager.job.task". |
String |
getMetricIdentifier(String metricName)
Returns the fully qualified metric name, for example
"host-7.taskmanager-2.window_word_count.my-mapper.metricName". |
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". |
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". |
QueryScopeInfo |
getQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter)
Returns the metric query service scope for this group.
|
String[] |
getScopeComponents()
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> |
histogram(String name,
H histogram) |
boolean |
isClosed() |
<M extends org.apache.flink.metrics.Meter> |
meter(String name,
M meter) |
protected void |
putVariables(Map<String,String> variables)
Enters all variables specific to this
AbstractMetricGroup and their associated values
into the map. |
protected static final org.slf4j.Logger LOG
protected final A extends AbstractMetricGroup<?> parent
protected volatile Map<String,String>[] variables
protected final MetricRegistry registry
protected QueryScopeInfo queryServiceScopeInfo
public AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent)
public Map<String,String> getAllVariables()
getAllVariables in interface org.apache.flink.metrics.MetricGrouppublic Map<String,String> getAllVariables(int reporterIndex, Set<String> excludedVariables)
protected void putVariables(Map<String,String> variables)
AbstractMetricGroup and their associated values
into the map.variables - map to enter variables and their values intopublic String getLogicalScope(org.apache.flink.metrics.CharacterFilter filter)
"taskmanager.job.task".filter - character filter which is applied to the scope componentspublic String getLogicalScope(org.apache.flink.metrics.CharacterFilter filter, char delimiter)
"taskmanager.job.task".filter - character filter which is applied to the scope componentsprotected String createLogicalScope(org.apache.flink.metrics.CharacterFilter filter, char delimiter)
protected abstract String getGroupName(org.apache.flink.metrics.CharacterFilter filter)
filter - character filter which is applied to the namepublic String[] getScopeComponents()
["host-7",
"taskmanager-2", "window_word_count", "my-mapper"].getScopeComponents in interface org.apache.flink.metrics.MetricGroupgetMetricIdentifier(String)public QueryScopeInfo getQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter)
filter - character filterprotected abstract QueryScopeInfo createQueryServiceMetricInfo(org.apache.flink.metrics.CharacterFilter filter)
filter - character filterpublic String getMetricIdentifier(String metricName)
"host-7.taskmanager-2.window_word_count.my-mapper.metricName".getMetricIdentifier in interface org.apache.flink.metrics.MetricGroupmetricName - metric namepublic String getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter)
"host-7.taskmanager-2.window_word_count.my-mapper.metricName".getMetricIdentifier in interface org.apache.flink.metrics.MetricGroupmetricName - metric namefilter - character filter which is applied to the scope components if not null.public String getMetricIdentifier(String metricName, org.apache.flink.metrics.CharacterFilter filter, int reporterIndex, char delimiter)
"host-7.taskmanager-2.window_word_count.my-mapper.metricName".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 usepublic void close()
public final boolean isClosed()
public void addSpan(org.apache.flink.traces.SpanBuilder spanBuilder)
addSpan in interface org.apache.flink.metrics.MetricGrouppublic org.apache.flink.metrics.Counter counter(String name)
counter in interface org.apache.flink.metrics.MetricGrouppublic <C extends org.apache.flink.metrics.Counter> C counter(String name, C counter)
counter in interface org.apache.flink.metrics.MetricGrouppublic <T,G extends org.apache.flink.metrics.Gauge<T>> G gauge(String name, G gauge)
gauge in interface org.apache.flink.metrics.MetricGrouppublic <H extends org.apache.flink.metrics.Histogram> H histogram(String name, H histogram)
histogram in interface org.apache.flink.metrics.MetricGrouppublic <M extends org.apache.flink.metrics.Meter> M meter(String name, M meter)
meter in interface org.apache.flink.metrics.MetricGroupprotected void addMetric(String name, org.apache.flink.metrics.Metric metric)
name - the name to register the metric undermetric - the metric to registerpublic org.apache.flink.metrics.MetricGroup addGroup(String name)
addGroup in interface org.apache.flink.metrics.MetricGrouppublic org.apache.flink.metrics.MetricGroup addGroup(String key, String value)
addGroup in interface org.apache.flink.metrics.MetricGroupprotected GenericMetricGroup createChildGroup(String name, AbstractMetricGroup.ChildType childType)
Copyright © 2014–2025 The Apache Software Foundation. All rights reserved.