org.apache.hadoop.metrics2.lib
Class MetricsRegistry

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

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class MetricsRegistry
extends Object

An optional metrics registry class for creating and maintaining a collection of MetricsMutables, making writing metrics source easier.


Constructor Summary
MetricsRegistry(MetricsInfo info)
          Construct the registry with a metadata object
MetricsRegistry(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.
 MutableMetric get(String name)
          Get a metric by name
 MetricsTag getTag(String name)
          Get a tag by name
 MetricsInfo info()
           
 MutableCounterInt newCounter(MetricsInfo info, int iVal)
          Create a mutable integer counter
 MutableCounterLong newCounter(MetricsInfo info, long iVal)
          Create a mutable long integer counter
 MutableCounterInt newCounter(String name, String desc, int iVal)
          Create a mutable integer counter
 MutableCounterLong newCounter(String name, String desc, long iVal)
          Create a mutable long integer counter
 MutableGaugeInt newGauge(MetricsInfo info, int iVal)
          Create a mutable integer gauge
 MutableGaugeLong newGauge(MetricsInfo info, long iVal)
          Create a mutable long integer gauge
 MutableGaugeInt newGauge(String name, String desc, int iVal)
          Create a mutable integer gauge
 MutableGaugeLong newGauge(String name, String desc, long iVal)
          Create a mutable long integer gauge
 MutableQuantiles newQuantiles(String name, String desc, String sampleName, String valueName, int interval)
          Create a mutable metric that estimates quantiles of a stream of values
 MutableRate newRate(String name)
          Create a mutable rate metric
 MutableRate newRate(String name, String description)
          Create a mutable rate metric
 MutableRate newRate(String name, String desc, boolean extended)
          Create a mutable rate metric (for throughput measurement)
 MutableStat newStat(String name, String desc, String sampleName, String valueName)
          Create a mutable metric with stats
 MutableStat newStat(String name, String desc, String sampleName, String valueName, boolean extended)
          Create a mutable metric with stats
 MetricsRegistry 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
 MetricsRegistry tag(MetricsInfo info, String value)
           
 MetricsRegistry tag(MetricsInfo info, String value, boolean override)
          Add a tag to the metrics
 MetricsRegistry tag(String name, String description, String value)
          Add a tag to the metrics
 MetricsRegistry 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

MetricsRegistry

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

Parameters:
name - of the record of the metrics

MetricsRegistry

public MetricsRegistry(MetricsInfo info)
Construct the registry with a metadata object

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

info

public MetricsInfo info()
Returns:
the info object of the metrics registry

get

public MutableMetric get(String name)
Get a metric by name

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

getTag

public MetricsTag getTag(String name)
Get a tag by name

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

newCounter

public 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 MutableCounterInt newCounter(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 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 MutableCounterLong newCounter(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 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 MutableGaugeInt newGauge(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 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 MutableGaugeLong newGauge(MetricsInfo info,
                                 long iVal)
Create a mutable long integer gauge

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

newQuantiles

public MutableQuantiles newQuantiles(String name,
                                     String desc,
                                     String sampleName,
                                     String valueName,
                                     int interval)
Create a mutable metric that estimates quantiles of a stream of values

Parameters:
name - of the metric
desc - metric description
sampleName - of the metric (e.g., "Ops")
valueName - of the metric (e.g., "Time" or "Latency")
interval - rollover interval of estimator in seconds
Returns:
a new quantile estimator object

newStat

public 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 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 MutableRate newRate(String name)
Create a mutable rate metric

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

newRate

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

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 MetricsRegistry setContext(String name)
Set the metrics context tag

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

tag

public MetricsRegistry 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 MetricsRegistry 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 MetricsRegistry tag(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 MetricsRegistry tag(MetricsInfo info,
                           String value)

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.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 Apache Software Foundation. All Rights Reserved.