public abstract class 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 | Field and Description |
---|---|
protected MetricRegistry |
registry
The registry that this metrics group belongs to
|
Constructor and Description |
---|
AbstractMetricGroup(MetricRegistry registry,
String[] scope) |
Modifier and Type | Method and Description |
---|---|
MetricGroup |
addGroup(int name)
Creates a new MetricGroup and adds it to this groups sub-groups.
|
MetricGroup |
addGroup(String name)
Creates a new MetricGroup and adds it to this groups sub-groups.
|
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 |
close() |
Counter |
counter(int name)
Creates and registers a new
Counter with Flink. |
<C extends Counter> |
counter(int name,
C counter)
Registers a
Counter with Flink. |
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. |
<T,G extends Gauge<T>> |
gauge(int name,
G gauge)
Registers a new
Gauge with Flink. |
<T,G extends Gauge<T>> |
gauge(String name,
G gauge)
Registers a new
Gauge with Flink. |
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[] |
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(int name,
H histogram)
Registers a new
Histogram with Flink. |
<H extends Histogram> |
histogram(String name,
H histogram)
Registers a new
Histogram with Flink. |
boolean |
isClosed() |
protected final MetricRegistry registry
public AbstractMetricGroup(MetricRegistry registry, String[] scope)
public String[] getScopeComponents()
["host-7", "taskmanager-2", "window_word_count", "my-mapper"]
getScopeComponents
in interface MetricGroup
getMetricIdentifier(String)
public 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 void close()
public final boolean isClosed()
public Counter counter(int name)
MetricGroup
Counter
with Flink.counter
in interface MetricGroup
name
- name of the counterpublic Counter counter(String name)
MetricGroup
Counter
with Flink.counter
in interface MetricGroup
name
- name of the counterpublic <C extends Counter> C counter(int name, C counter)
MetricGroup
Counter
with Flink.counter
in interface MetricGroup
C
- counter typename
- name of the countercounter
- counter to registerpublic <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(int name, G gauge)
MetricGroup
Gauge
with Flink.gauge
in interface MetricGroup
T
- return type of the gaugename
- name of the gaugegauge
- gauge 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(int name, H histogram)
MetricGroup
Histogram
with Flink.histogram
in interface MetricGroup
H
- histogram typename
- name of the histogramhistogram
- histogram 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 registerprotected void addMetric(String name, Metric metric)
name
- the name to register the metric undermetric
- the metric to registerpublic MetricGroup addGroup(int name)
MetricGroup
addGroup
in interface MetricGroup
name
- name of the grouppublic MetricGroup addGroup(String name)
MetricGroup
addGroup
in interface MetricGroup
name
- name of the groupCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.