org.apache.hadoop.metrics2.lib
Class DynamicMetricsRegistry

java.lang.Object
  extended by org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry

@InterfaceAudience.Private
public class DynamicMetricsRegistry
extends Object

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.


Constructor Summary
DynamicMetricsRegistry(org.apache.hadoop.metrics2.MetricsInfo info)
          Construct the registry with a metadata object
DynamicMetricsRegistry(String name)
          Construct the registry with a record name
 
Method Summary
 void add(String name, long value)
          Add sample to a stat metric by name.
 void clearMetrics()
           
 org.apache.hadoop.metrics2.lib.MutableMetric get(String name)
          Get a metric by name
 MutableHistogram getHistogram(String histoName)
           
 org.apache.hadoop.metrics2.lib.MutableCounterLong getLongCounter(String counterName, long potentialStartingValue)
          Get a MetricMutableCounterLong from the storage.
 org.apache.hadoop.metrics2.lib.MutableGaugeLong getLongGauge(String gaugeName, long potentialStartingValue)
          Get a MetricMutableGaugeLong from the storage.
 MetricMutableQuantiles getQuantile(String histoName)
           
 org.apache.hadoop.metrics2.MetricsTag getTag(String name)
          Get a tag by name
 org.apache.hadoop.metrics2.MetricsInfo info()
           
 org.apache.hadoop.metrics2.lib.MutableCounterInt newCounter(org.apache.hadoop.metrics2.MetricsInfo info, int iVal)
          Create a mutable integer counter
 org.apache.hadoop.metrics2.lib.MutableCounterLong newCounter(org.apache.hadoop.metrics2.MetricsInfo info, long iVal)
          Create a mutable long integer counter
 org.apache.hadoop.metrics2.lib.MutableCounterInt newCounter(String name, String desc, int iVal)
          Create a mutable integer counter
 org.apache.hadoop.metrics2.lib.MutableCounterLong newCounter(String name, String desc, long iVal)
          Create a mutable long integer counter
 org.apache.hadoop.metrics2.lib.MutableGaugeInt newGauge(org.apache.hadoop.metrics2.MetricsInfo info, int iVal)
          Create a mutable integer gauge
 org.apache.hadoop.metrics2.lib.MutableGaugeLong newGauge(org.apache.hadoop.metrics2.MetricsInfo info, long iVal)
          Create a mutable long integer gauge
 org.apache.hadoop.metrics2.lib.MutableGaugeInt newGauge(String name, String desc, int iVal)
          Create a mutable integer gauge
 org.apache.hadoop.metrics2.lib.MutableGaugeLong newGauge(String name, String desc, long iVal)
          Create a mutable long integer gauge
 MutableHistogram newHistogram(String name)
          Create a new histogram.
 MutableHistogram newHistogram(String name, String desc)
          Create a new histogram.
 MetricMutableQuantiles newQuantile(String name)
          Create a new MutableQuantile(A more accurate histogram).
 MetricMutableQuantiles newQuantile(String name, String desc)
           
 org.apache.hadoop.metrics2.lib.MutableRate newRate(String name)
          Create a mutable rate metric
 org.apache.hadoop.metrics2.lib.MutableRate newRate(String name, String description)
          Create a mutable rate metric
 org.apache.hadoop.metrics2.lib.MutableRate newRate(String name, String desc, boolean extended)
          Create a mutable rate metric (for throughput measurement)
 org.apache.hadoop.metrics2.lib.MutableRate newRate(String name, String desc, boolean extended, boolean returnExisting)
           
 org.apache.hadoop.metrics2.lib.MutableStat newStat(String name, String desc, String sampleName, String valueName)
          Create a mutable metric with stats
 org.apache.hadoop.metrics2.lib.MutableStat newStat(String name, String desc, String sampleName, String valueName, boolean extended)
          Create a mutable metric with stats
 void removeMetric(String name)
          Removes metric by name
 DynamicMetricsRegistry setContext(String name)
          Set the metrics context tag
 void snapshot(org.apache.hadoop.metrics2.MetricsRecordBuilder builder, boolean all)
          Sample all the mutable metrics and put the snapshot in the builder
 DynamicMetricsRegistry tag(org.apache.hadoop.metrics2.MetricsInfo info, String value)
           
 DynamicMetricsRegistry tag(org.apache.hadoop.metrics2.MetricsInfo info, String value, boolean override)
          Add a tag to the metrics
 DynamicMetricsRegistry tag(String name, String description, String value)
          Add a tag to the metrics
 DynamicMetricsRegistry tag(String name, String description, String value, boolean override)
          Add a tag to the metrics
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DynamicMetricsRegistry

public DynamicMetricsRegistry(String name)
Construct the registry with a record name

Parameters:
name - of the record of the metrics

DynamicMetricsRegistry

public DynamicMetricsRegistry(org.apache.hadoop.metrics2.MetricsInfo info)
Construct the registry with a metadata object

Parameters:
info - the info object for the metrics record/group
Method Detail

info

public org.apache.hadoop.metrics2.MetricsInfo info()
Returns:
the info object of the metrics registry

get

public org.apache.hadoop.metrics2.lib.MutableMetric get(String name)
Get a metric by name

Parameters:
name - of the metric
Returns:
the metric object

getTag

public org.apache.hadoop.metrics2.MetricsTag getTag(String name)
Get a tag by name

Parameters:
name - of the tag
Returns:
the tag object

newCounter

public org.apache.hadoop.metrics2.lib.MutableCounterInt newCounter(String name,
                                                                   String desc,
                                                                   int iVal)
Create a mutable integer counter

Parameters:
name - of the metric
desc - metric description
iVal - initial value
Returns:
a new counter object

newCounter

public org.apache.hadoop.metrics2.lib.MutableCounterInt newCounter(org.apache.hadoop.metrics2.MetricsInfo info,
                                                                   int iVal)
Create a mutable integer counter

Parameters:
info - metadata of the metric
iVal - initial value
Returns:
a new counter object

newCounter

public org.apache.hadoop.metrics2.lib.MutableCounterLong newCounter(String name,
                                                                    String desc,
                                                                    long iVal)
Create a mutable long integer counter

Parameters:
name - of the metric
desc - metric description
iVal - initial value
Returns:
a new counter object

newCounter

public org.apache.hadoop.metrics2.lib.MutableCounterLong newCounter(org.apache.hadoop.metrics2.MetricsInfo info,
                                                                    long iVal)
Create a mutable long integer counter

Parameters:
info - metadata of the metric
iVal - initial value
Returns:
a new counter object

newGauge

public org.apache.hadoop.metrics2.lib.MutableGaugeInt newGauge(String name,
                                                               String desc,
                                                               int iVal)
Create a mutable integer gauge

Parameters:
name - of the metric
desc - metric description
iVal - initial value
Returns:
a new gauge object

newGauge

public org.apache.hadoop.metrics2.lib.MutableGaugeInt newGauge(org.apache.hadoop.metrics2.MetricsInfo info,
                                                               int iVal)
Create a mutable integer gauge

Parameters:
info - metadata of the metric
iVal - initial value
Returns:
a new gauge 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 metric
desc - metric description
iVal - 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 metric
iVal - 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 metric
desc - metric description
sampleName - 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 metric
desc - metric description
sampleName - of the metric (e.g., "Ops")
valueName - of the metric (e.g., "Time" or "Latency")
Returns:
a new mutable metric object

newRate

public org.apache.hadoop.metrics2.lib.MutableRate newRate(String name)
Create a mutable rate metric

Parameters:
name - of the metric
Returns:
a new mutable metric object

newRate

public org.apache.hadoop.metrics2.lib.MutableRate newRate(String name,
                                                          String description)
Create a mutable rate metric

Parameters:
name - of the metric
description - 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 metric
desc - description
extended - produce extended stat (stdev/min/max etc.) if true
Returns:
a new mutable rate metric object

newRate

@InterfaceAudience.Private
public org.apache.hadoop.metrics2.lib.MutableRate newRate(String name,
                                                                                    String desc,
                                                                                    boolean extended,
                                                                                    boolean returnExisting)

newHistogram

public MutableHistogram newHistogram(String name)
Create a new histogram.

Parameters:
name - Name of the histogram.
Returns:
A new MutableHistogram

newHistogram

public MutableHistogram newHistogram(String name,
                                     String desc)
Create a new histogram.

Parameters:
name - The name of the histogram
desc - The description of the data in the histogram.
Returns:
A new MutableHistogram

newQuantile

public MetricMutableQuantiles newQuantile(String name)
Create a new MutableQuantile(A more accurate histogram).

Parameters:
name - The name of the histogram
Returns:
a new MutableQuantile

newQuantile

public MetricMutableQuantiles newQuantile(String name,
                                          String desc)

add

public void add(String name,
                long value)
Add sample to a stat metric by name.

Parameters:
name - of the metric
value - of the snapshot to add

setContext

public DynamicMetricsRegistry setContext(String name)
Set the metrics context tag

Parameters:
name - of the context
Returns:
the registry itself as a convenience

tag

public DynamicMetricsRegistry tag(String name,
                                  String description,
                                  String value)
Add a tag to the metrics

Parameters:
name - of the tag
description - of the tag
value - of the tag
Returns:
the registry (for keep adding tags)

tag

public DynamicMetricsRegistry tag(String name,
                                  String description,
                                  String value,
                                  boolean override)
Add a tag to the metrics

Parameters:
name - of the tag
description - of the tag
value - of the tag
override - 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 tag
value - of the tag
override - existing tag if true
Returns:
the registry (for keep adding tags etc.)

tag

public DynamicMetricsRegistry tag(org.apache.hadoop.metrics2.MetricsInfo info,
                                  String value)

snapshot

public void snapshot(org.apache.hadoop.metrics2.MetricsRecordBuilder builder,
                     boolean all)
Sample all the mutable metrics and put the snapshot in the builder

Parameters:
builder - to contain the metrics snapshot
all - get all the metrics even if the values are not changed.

toString

public String toString()
Overrides:
toString in class Object

removeMetric

public void removeMetric(String name)
Removes metric by name

Parameters:
name - name of the metric to remove

getLongGauge

public org.apache.hadoop.metrics2.lib.MutableGaugeLong getLongGauge(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.

getLongCounter

public org.apache.hadoop.metrics2.lib.MutableCounterLong getLongCounter(String counterName,
                                                                        long potentialStartingValue)
Get a MetricMutableCounterLong from the storage. If it is not there atomically put it.

Parameters:
counterName - Name of the counter to get
potentialStartingValue - starting value if we have to create a new counter

getHistogram

public MutableHistogram getHistogram(String histoName)

getQuantile

public MetricMutableQuantiles getQuantile(String histoName)

clearMetrics

public void clearMetrics()


Copyright © 2015 The Apache Software Foundation. All rights reserved.