Package org.apache.hadoop.metrics2.lib
Class DynamicMetricsRegistry
java.lang.Object
org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry
An optional metrics registry class for creating and maintaining a collection of MetricsMutables,
making writing metrics source easier. NOTE: this is a copy of
org.apache.hadoop.metrics2.lib.MetricsRegistry with added one feature: metrics can be removed.
When HADOOP-8313 is fixed, usages of this class should be substituted with
org.apache.hadoop.metrics2.lib.MetricsRegistry. This implementation also provides handy methods
for creating metrics dynamically. Another difference is that metricsMap implementation is
substituted with thread-safe map, as we allow dynamic metrics additions/removals.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final DefaultMetricsSystemHelper
private static final String[]
private final org.apache.hadoop.metrics2.MetricsInfo
private final ConcurrentMap<String,
org.apache.hadoop.metrics2.lib.MutableMetric> private final ConcurrentMap<String,
org.apache.hadoop.metrics2.MetricsTag> -
Constructor Summary
ConstructorDescriptionDynamicMetricsRegistry
(String name) Construct the registry with a record nameDynamicMetricsRegistry
(org.apache.hadoop.metrics2.MetricsInfo info) Construct the registry with a metadata object -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add sample to a stat metric by name.(package private) void
private <T extends org.apache.hadoop.metrics2.lib.MutableMetric>
TaddNewMetricIfAbsent
(String name, T ret, Class<T> metricClass) void
org.apache.hadoop.metrics2.lib.MutableMetric
Get a metric by namegetCounter
(String counterName, long potentialStartingValue) Get a MetricMutableCounterLong from the storage.org.apache.hadoop.metrics2.lib.MutableGaugeLong
Get a MetricMutableGaugeLong from the storage.org.apache.hadoop.metrics2.lib.MutableGaugeInt
getGaugeInt
(String gaugeName, int potentialStartingValue) Get a MetricMutableGaugeInt from the storage.getHistogram
(String histoName) ConcurrentMap<String,
org.apache.hadoop.metrics2.lib.MutableMetric> org.apache.hadoop.metrics2.MetricsTag
Get a tag by nameorg.apache.hadoop.metrics2.MetricsInfo
info()
Returns the info object of the metrics registry(package private) Collection<org.apache.hadoop.metrics2.lib.MutableMetric>
metrics()
newCounter
(String name, String desc, long iVal) Create a mutable long integer counternewCounter
(org.apache.hadoop.metrics2.MetricsInfo info, long iVal) Create a mutable long integer counterorg.apache.hadoop.metrics2.lib.MutableGaugeLong
Create a mutable long integer gaugeorg.apache.hadoop.metrics2.lib.MutableGaugeLong
newGauge
(org.apache.hadoop.metrics2.MetricsInfo info, long iVal) Create a mutable long integer gaugenewHistogram
(String name) Create a new histogram.newHistogram
(String name, String desc) Create a new histogram.org.apache.hadoop.metrics2.lib.MutableRate
Create a mutable rate metricorg.apache.hadoop.metrics2.lib.MutableRate
Create a mutable rate metricorg.apache.hadoop.metrics2.lib.MutableRate
Create a mutable rate metric (for throughput measurement)org.apache.hadoop.metrics2.lib.MutableRate
newSizeHistogram
(String name) Create a new histogram with size range counts.newSizeHistogram
(String name, String desc) Create a new histogram with size range counts.org.apache.hadoop.metrics2.lib.MutableStat
Create a mutable metric with statsorg.apache.hadoop.metrics2.lib.MutableStat
Create a mutable metric with statsnewTimeHistogram
(String name) Create a new histogram with time range counts.newTimeHistogram
(String name, String desc) Create a new histogram with time range counts.void
removeHistogramMetrics
(String baseName) void
removeMetric
(String name) Removes metric by nameprivate <T> T
returnExistingWithCast
(org.apache.hadoop.metrics2.lib.MutableMetric metric, Class<T> metricClass, String name) setContext
(String name) Set the metrics context tagvoid
snapshot
(org.apache.hadoop.metrics2.MetricsRecordBuilder builder, boolean all) Sample all the mutable metrics and put the snapshot in the builderAdd a tag to the metricsAdd a tag to the metricsAdd a tag to the metrics(package private) Collection<org.apache.hadoop.metrics2.MetricsTag>
tags()
toString()
-
Field Details
-
metricsMap
-
tagsMap
-
metricsInfo
-
helper
-
histogramSuffixes
-
-
Constructor Details
-
DynamicMetricsRegistry
Construct the registry with a record name- Parameters:
name
- of the record of the metrics
-
DynamicMetricsRegistry
Construct the registry with a metadata object- Parameters:
info
- the info object for the metrics record/group
-
-
Method Details
-
info
Returns the info object of the metrics registry -
get
Get a metric by name- Parameters:
name
- of the metric- Returns:
- the metric object
-
getTag
Get a tag by name- Parameters:
name
- of the tag- Returns:
- the tag object
-
newCounter
Create a mutable long integer counter- Parameters:
name
- of the metricdesc
- metric descriptioniVal
- initial value- Returns:
- a new counter object
-
newCounter
Create a mutable long integer counter- Parameters:
info
- metadata of the metriciVal
- initial value- Returns:
- a new counter object
-
newGauge
public org.apache.hadoop.metrics2.lib.MutableGaugeLong newGauge(String name, String desc, long iVal) Create a mutable long integer gauge- Parameters:
name
- of the metricdesc
- metric descriptioniVal
- initial value- Returns:
- a new gauge object
-
newGauge
public org.apache.hadoop.metrics2.lib.MutableGaugeLong newGauge(org.apache.hadoop.metrics2.MetricsInfo info, long iVal) Create a mutable long integer gauge- Parameters:
info
- metadata of the metriciVal
- initial value- Returns:
- a new gauge object
-
newStat
public org.apache.hadoop.metrics2.lib.MutableStat newStat(String name, String desc, String sampleName, String valueName, boolean extended) Create a mutable metric with stats- Parameters:
name
- of the metricdesc
- metric descriptionsampleName
- of the metric (e.g., "Ops")valueName
- of the metric (e.g., "Time" or "Latency")extended
- produce extended stat (stdev, min/max etc.) if true.- Returns:
- a new mutable stat metric object
-
newStat
public org.apache.hadoop.metrics2.lib.MutableStat newStat(String name, String desc, String sampleName, String valueName) Create a mutable metric with stats- Parameters:
name
- of the metricdesc
- metric descriptionsampleName
- of the metric (e.g., "Ops")valueName
- of the metric (e.g., "Time" or "Latency")- Returns:
- a new mutable metric object
-
newRate
Create a mutable rate metric- Parameters:
name
- of the metric- Returns:
- a new mutable metric object
-
newRate
Create a mutable rate metric- Parameters:
name
- of the metricdescription
- of the metric- Returns:
- a new mutable rate metric object
-
newRate
public org.apache.hadoop.metrics2.lib.MutableRate newRate(String name, String desc, boolean extended) Create a mutable rate metric (for throughput measurement)- Parameters:
name
- of the metricdesc
- descriptionextended
- produce extended stat (stdev/min/max etc.) if true- Returns:
- a new mutable rate metric object
-
newRate
-
newHistogram
Create a new histogram.- Parameters:
name
- Name of the histogram.- Returns:
- A new MutableHistogram
-
newHistogram
Create a new histogram.- Parameters:
name
- The name of the histogramdesc
- The description of the data in the histogram.- Returns:
- A new MutableHistogram
-
newTimeHistogram
Create a new histogram with time range counts.- Parameters:
name
- Name of the histogram.- Returns:
- A new MutableTimeHistogram
-
newTimeHistogram
Create a new histogram with time range counts.- Parameters:
name
- The name of the histogramdesc
- The description of the data in the histogram.- Returns:
- A new MutableTimeHistogram
-
newSizeHistogram
Create a new histogram with size range counts.- Parameters:
name
- Name of the histogram.- Returns:
- A new MutableSizeHistogram
-
newSizeHistogram
Create a new histogram with size range counts.- Parameters:
name
- The name of the histogramdesc
- The description of the data in the histogram.- Returns:
- A new MutableSizeHistogram
-
add
-
add
Add sample to a stat metric by name.- Parameters:
name
- of the metricvalue
- of the snapshot to add
-
setContext
Set the metrics context tag- Parameters:
name
- of the context- Returns:
- the registry itself as a convenience
-
tag
Add a tag to the metrics- Parameters:
name
- of the tagdescription
- of the tagvalue
- of the tag- Returns:
- the registry (for keep adding tags)
-
tag
Add a tag to the metrics- Parameters:
name
- of the tagdescription
- of the tagvalue
- of the tagoverride
- existing tag if true- Returns:
- the registry (for keep adding tags)
-
tag
public DynamicMetricsRegistry tag(org.apache.hadoop.metrics2.MetricsInfo info, String value, boolean override) Add a tag to the metrics- Parameters:
info
- metadata of the tagvalue
- of the tagoverride
- existing tag if true- Returns:
- the registry (for keep adding tags etc.)
-
tag
-
tags
Collection<org.apache.hadoop.metrics2.MetricsTag> tags() -
metrics
Collection<org.apache.hadoop.metrics2.lib.MutableMetric> metrics() -
snapshot
Sample all the mutable metrics and put the snapshot in the builder- Parameters:
builder
- to contain the metrics snapshotall
- get all the metrics even if the values are not changed.
-
toString
-
removeMetric
Removes metric by name- Parameters:
name
- name of the metric to remove
-
removeHistogramMetrics
-
getGauge
public org.apache.hadoop.metrics2.lib.MutableGaugeLong getGauge(String gaugeName, long potentialStartingValue) Get a MetricMutableGaugeLong from the storage. If it is not there atomically put it.- Parameters:
gaugeName
- name of the gauge to create or get.potentialStartingValue
- value of the new gauge if we have to create it.
-
getGaugeInt
public org.apache.hadoop.metrics2.lib.MutableGaugeInt getGaugeInt(String gaugeName, int potentialStartingValue) Get a MetricMutableGaugeInt from the storage. If it is not there atomically put it.- Parameters:
gaugeName
- name of the gauge to create or get.potentialStartingValue
- value of the new gauge if we have to create it.
-
getCounter
Get a MetricMutableCounterLong from the storage. If it is not there atomically put it.- Parameters:
counterName
- Name of the counter to getpotentialStartingValue
- starting value if we have to create a new counter
-
getHistogram
-
addNewMetricIfAbsent
private <T extends org.apache.hadoop.metrics2.lib.MutableMetric> T addNewMetricIfAbsent(String name, T ret, Class<T> metricClass) -
returnExistingWithCast
private <T> T returnExistingWithCast(org.apache.hadoop.metrics2.lib.MutableMetric metric, Class<T> metricClass, String name) -
clearMetrics
-
getMetricsMap
-