org.apache.hadoop.metrics2.lib
Class DynamicMetricsRegistry

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

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 & tagsMap implementation is substituted with concurrent map, as we allow dynamic metrics additions/removals.


Field Summary
static String CONTEXT_DESC
          description for the context tag
static String CONTEXT_KEY
          key for the context tag
 
Constructor Summary
DynamicMetricsRegistry(String name)
          Construct the registry with a record name
DynamicMetricsRegistry(String name, org.apache.hadoop.metrics2.lib.MetricMutableFactory factory)
          Construct the registry with a name and a metric factory
 
Method Summary
 void clearMetrics()
           
 org.apache.hadoop.metrics2.lib.MetricMutable get(String name)
          Get a metric by name
 MetricMutableHistogram getHistogram(String histoName)
           
 org.apache.hadoop.metrics2.lib.MetricMutableCounterLong getLongCounter(String counterName, long potentialStartingValue)
          Get a MetricMutableCounterLong from the storage.
 org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong getLongGauge(String gaugeName, long potentialStartingValue)
          Get a MetricMutableGaugeLong from the storage.
 MetricMutableQuantiles getQuantile(String histoName)
           
 Set<Map.Entry<String,org.apache.hadoop.metrics2.lib.MetricMutable>> metrics()
          Get the metrics
 String name()
           
 org.apache.hadoop.metrics2.lib.MetricMutableCounterInt newCounter(String name, String description, int initValue)
          Create a mutable integer counter
 org.apache.hadoop.metrics2.lib.MetricMutableCounterLong newCounter(String name, String description, long initValue)
          Create a mutable long integer counter
 org.apache.hadoop.metrics2.lib.MetricMutableGaugeInt newGauge(String name, String description, int initValue)
          Create a mutable integer gauge
 org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong newGauge(String name, String description, long initValue)
          Create a mutable long integer gauge
 MetricMutableHistogram newHistogram(String name)
          Create a new histogram.
 MetricMutableHistogram 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)
          Create a new MutableQuantile(A more accurate histogram).
 MetricMutableSizeHistogram newSizeHistogram(String name)
          Create a new histogram with size range counts.
 MetricMutableSizeHistogram newSizeHistogram(String name, String desc)
          Create a new histogram with size range counts.
 org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name)
          Create a mutable metric with stats using the name only
 org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name, String description, String sampleName, String valueName)
          Create a mutable metric with stats
 org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name, String description, String sampleName, String valueName, boolean extended)
          Create a mutable metric with stats
 MetricMutableTimeHistogram newTimeHistogram(String name)
          Create a new histogram with time range counts.
 MetricMutableTimeHistogram newTimeHistogram(String name, String desc)
          Create a new histogram with time range counts.
 void removeMetric(String name)
          Removes metric by name
 DynamicMetricsRegistry setContext(String name)
          Set the metrics context tag
 void snapshot(MetricsRecordBuilder builder, boolean all)
          Sample all the mutable metrics and put the snapshot in the builder
 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
 Set<Map.Entry<String,MetricsTag>> tags()
          Get the tags
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_KEY

public static final String CONTEXT_KEY
key for the context tag

See Also:
Constant Field Values

CONTEXT_DESC

public static final String CONTEXT_DESC
description for the context tag

See Also:
Constant Field Values
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(String name,
                              org.apache.hadoop.metrics2.lib.MetricMutableFactory factory)
Construct the registry with a name and a metric factory

Parameters:
name - of the record of the metrics
factory - for creating new mutable metrics
Method Detail

name

public String name()
Returns:
the name of the metrics registry

get

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

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

newCounter

public org.apache.hadoop.metrics2.lib.MetricMutableCounterInt newCounter(String name,
                                                                         String description,
                                                                         int initValue)
Create a mutable integer counter

Parameters:
name - of the metric
description - of the metric
initValue - of the metric
Returns:
a new counter object

newCounter

public org.apache.hadoop.metrics2.lib.MetricMutableCounterLong newCounter(String name,
                                                                          String description,
                                                                          long initValue)
Create a mutable long integer counter

Parameters:
name - of the metric
description - of the metric
initValue - of the metric
Returns:
a new counter object

newGauge

public org.apache.hadoop.metrics2.lib.MetricMutableGaugeInt newGauge(String name,
                                                                     String description,
                                                                     int initValue)
Create a mutable integer gauge

Parameters:
name - of the metric
description - of the metric
initValue - of the metric
Returns:
a new gauge object

newGauge

public org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong newGauge(String name,
                                                                      String description,
                                                                      long initValue)
Create a mutable long integer gauge

Parameters:
name - of the metric
description - of the metric
initValue - of the metric
Returns:
a new gauge object

newStat

public org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name,
                                                                String description,
                                                                String sampleName,
                                                                String valueName,
                                                                boolean extended)
Create a mutable metric with stats

Parameters:
name - of the metric
description - of the metric
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 metric object

newStat

public org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name,
                                                                String description,
                                                                String sampleName,
                                                                String valueName)
Create a mutable metric with stats

Parameters:
name - of the metric
description - of the metric
sampleName - of the metric (e.g., "ops")
valueName - of the metric (e.g., "time" or "latency")
Returns:
a new metric object

newStat

public org.apache.hadoop.metrics2.lib.MetricMutableStat newStat(String name)
Create a mutable metric with stats using the name only

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

newHistogram

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

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

newHistogram

public MetricMutableHistogram 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

newTimeHistogram

public MetricMutableTimeHistogram newTimeHistogram(String name)
Create a new histogram with time range counts.

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

newTimeHistogram

public MetricMutableTimeHistogram newTimeHistogram(String name,
                                                   String desc)
Create a new histogram with time range counts.

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

newSizeHistogram

public MetricMutableSizeHistogram newSizeHistogram(String name)
Create a new histogram with size range counts.

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

newSizeHistogram

public MetricMutableSizeHistogram newSizeHistogram(String name,
                                                   String desc)
Create a new histogram with size range counts.

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

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)
Create a new MutableQuantile(A more accurate histogram).

Parameters:
name - The name of the histogram
desc - Description of the data.
Returns:
a new MutableQuantile

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)

tags

public Set<Map.Entry<String,MetricsTag>> tags()
Get the tags

Returns:
the tags set

metrics

public Set<Map.Entry<String,org.apache.hadoop.metrics2.lib.MetricMutable>> metrics()
Get the metrics

Returns:
the metrics set

snapshot

public void snapshot(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.

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.MetricMutableGaugeLong 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 counter if we have to create it.
Returns:
a metric object

getLongCounter

public org.apache.hadoop.metrics2.lib.MetricMutableCounterLong 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
Returns:
a metric object

getHistogram

public MetricMutableHistogram getHistogram(String histoName)

getQuantile

public MetricMutableQuantiles getQuantile(String histoName)

clearMetrics

public void clearMetrics()


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.