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(int name) |
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 |
close() |
org.apache.flink.metrics.Counter |
counter(int name) |
<C extends org.apache.flink.metrics.Counter> |
counter(int name,
C counter) |
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 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(int name,
G gauge) |
<T,G extends org.apache.flink.metrics.Gauge<T>> |
gauge(String name,
G gauge) |
Map<String,String> |
getAllVariables() |
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)
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(int name,
H histogram) |
<H extends org.apache.flink.metrics.Histogram> |
histogram(String name,
H histogram) |
boolean |
isClosed() |
<M extends org.apache.flink.metrics.Meter> |
meter(int name,
M meter) |
<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.MetricGroup
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 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.MetricGroup
getMetricIdentifier(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.MetricGroup
metricName
- 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.MetricGroup
metricName
- 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)
"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 usedpublic void close()
public final boolean isClosed()
public org.apache.flink.metrics.Counter counter(int name)
counter
in interface org.apache.flink.metrics.MetricGroup
public org.apache.flink.metrics.Counter counter(String name)
counter
in interface org.apache.flink.metrics.MetricGroup
public <C extends org.apache.flink.metrics.Counter> C counter(int name, C counter)
counter
in interface org.apache.flink.metrics.MetricGroup
public <C extends org.apache.flink.metrics.Counter> C counter(String name, C counter)
counter
in interface org.apache.flink.metrics.MetricGroup
public <T,G extends org.apache.flink.metrics.Gauge<T>> G gauge(int name, G gauge)
gauge
in interface org.apache.flink.metrics.MetricGroup
public <T,G extends org.apache.flink.metrics.Gauge<T>> G gauge(String name, G gauge)
gauge
in interface org.apache.flink.metrics.MetricGroup
public <H extends org.apache.flink.metrics.Histogram> H histogram(int name, H histogram)
histogram
in interface org.apache.flink.metrics.MetricGroup
public <H extends org.apache.flink.metrics.Histogram> H histogram(String name, H histogram)
histogram
in interface org.apache.flink.metrics.MetricGroup
public <M extends org.apache.flink.metrics.Meter> M meter(int name, M meter)
meter
in interface org.apache.flink.metrics.MetricGroup
public <M extends org.apache.flink.metrics.Meter> M meter(String name, M meter)
meter
in interface org.apache.flink.metrics.MetricGroup
protected 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(int name)
addGroup
in interface org.apache.flink.metrics.MetricGroup
public org.apache.flink.metrics.MetricGroup addGroup(String name)
addGroup
in interface org.apache.flink.metrics.MetricGroup
public org.apache.flink.metrics.MetricGroup addGroup(String key, String value)
addGroup
in interface org.apache.flink.metrics.MetricGroup
protected GenericMetricGroup createChildGroup(String name, AbstractMetricGroup.ChildType childType)
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.