A
- The type of the parent MetricGroup@Internal public abstract class AbstractMetricGroup<A extends AbstractMetricGroup<?>> extends Object implements 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 |
---|---|
MetricGroup |
addGroup(String name)
Creates a new MetricGroup and adds it to this groups sub-groups.
|
MetricGroup |
addGroup(String key,
String value)
Creates a new key-value MetricGroup pair.
|
protected void |
addMetric(String name,
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(SpanBuilder spanBuilder) |
void |
close() |
Counter |
counter(String name)
Creates and registers a new
Counter with Flink. |
<C extends Counter> |
counter(String name,
C counter)
Registers a
Counter with Flink. |
protected GenericMetricGroup |
createChildGroup(String name,
AbstractMetricGroup.ChildType childType) |
protected String |
createLogicalScope(CharacterFilter filter,
char delimiter) |
protected abstract QueryScopeInfo |
createQueryServiceMetricInfo(CharacterFilter filter)
Creates the metric query service scope for this group.
|
<T,G extends Gauge<T>> |
gauge(String name,
G gauge)
Registers a new
Gauge with Flink. |
Map<String,String> |
getAllVariables()
Returns a map of all variables and their associated value, for example
{"<host>"="host-7", "<tm_id>"="taskmanager-2"} . |
Map<String,String> |
getAllVariables(int reporterIndex,
Set<String> excludedVariables) |
protected abstract String |
getGroupName(CharacterFilter filter)
Returns the name for this group, meaning what kind of entity it represents, for example
"taskmanager".
|
String |
getLogicalScope(CharacterFilter filter)
Returns the logical scope of this group, for example
"taskmanager.job.task" . |
String |
getLogicalScope(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,
CharacterFilter filter)
Returns the fully qualified metric name, for example
"host-7.taskmanager-2.window_word_count.my-mapper.metricName" . |
String |
getMetricIdentifier(String metricName,
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(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 Histogram> |
histogram(String name,
H histogram)
Registers a new
Histogram with Flink. |
boolean |
isClosed() |
<M extends Meter> |
meter(String name,
M meter)
Registers a new
Meter with Flink. |
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()
MetricGroup
{"<host>"="host-7", "<tm_id>"="taskmanager-2"}
.getAllVariables
in interface MetricGroup
public 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(CharacterFilter filter)
"taskmanager.job.task"
.filter
- character filter which is applied to the scope componentspublic String getLogicalScope(CharacterFilter filter, char delimiter)
"taskmanager.job.task"
.filter
- character filter which is applied to the scope componentsprotected String createLogicalScope(CharacterFilter filter, char delimiter)
protected abstract String getGroupName(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 MetricGroup
getMetricIdentifier(String)
public QueryScopeInfo getQueryServiceMetricInfo(CharacterFilter filter)
filter
- character filterprotected abstract QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter)
filter
- character filterpublic String getMetricIdentifier(String metricName)
"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.getMetricIdentifier
in interface MetricGroup
metricName
- metric namepublic String getMetricIdentifier(String metricName, CharacterFilter filter)
"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.getMetricIdentifier
in interface MetricGroup
metricName
- metric namefilter
- character filter which is applied to the scope components if not null.public String getMetricIdentifier(String metricName, 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(SpanBuilder spanBuilder)
addSpan
in interface MetricGroup
public Counter counter(String name)
MetricGroup
Counter
with Flink.counter
in interface MetricGroup
name
- name of the counterpublic <C extends Counter> C counter(String name, C counter)
MetricGroup
Counter
with Flink.counter
in interface MetricGroup
C
- counter typename
- name of the countercounter
- counter to registerpublic <T,G extends Gauge<T>> G gauge(String name, G gauge)
MetricGroup
Gauge
with Flink.gauge
in interface MetricGroup
T
- return type of the gaugename
- name of the gaugegauge
- gauge to registerpublic <H extends Histogram> H histogram(String name, H histogram)
MetricGroup
Histogram
with Flink.histogram
in interface MetricGroup
H
- histogram typename
- name of the histogramhistogram
- histogram to registerpublic <M extends Meter> M meter(String name, M meter)
MetricGroup
Meter
with Flink.meter
in interface MetricGroup
M
- meter typename
- name of the metermeter
- meter to registerprotected void addMetric(String name, Metric metric)
name
- the name to register the metric undermetric
- the metric to registerpublic MetricGroup addGroup(String name)
MetricGroup
addGroup
in interface MetricGroup
name
- name of the grouppublic MetricGroup addGroup(String key, String value)
MetricGroup
The only difference between calling this method and group.addGroup(key).addGroup(value)
is that MetricGroup.getAllVariables()
of the value group
return an additional "<key>"="value"
pair.
addGroup
in interface MetricGroup
key
- name of the first groupvalue
- name of the second groupprotected GenericMetricGroup createChildGroup(String name, AbstractMetricGroup.ChildType childType)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.