org.apache.hadoop.metrics2.lib
Class MetricsRegistry

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

public class MetricsRegistry
extends Object

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


Field Summary
static String CONTEXT_DESC
          description for the context tag
static String CONTEXT_KEY
          key for the context tag
 
Constructor Summary
MetricsRegistry(String name)
          Construct the registry with a record name
MetricsRegistry(String name, MetricMutableFactory factory)
          Construct the registry with a name and a metric factory
 
Method Summary
 void add(String name, long value)
          Add a value to a metric by name.
 void add(String name, long value, MetricMutableFactory factory)
          Decrement a metric by name.
 void decr(String name)
          Decrement a metric by name.
 void decr(String name, MetricMutableFactory factory)
          Decrement a metric by name.
 MetricMutable get(String name)
          Get a metric by name
 void incr(String name)
          Increment a metric by name.
 void incr(String name, MetricMutableFactory factory)
          Increment a metric by name.
 Set<Map.Entry<String,MetricMutable>> metrics()
          Get the metrics
 String name()
           
 MetricMutableCounterInt newCounter(String name, String description, int initValue)
          Create a mutable integer counter
 MetricMutableCounterLong newCounter(String name, String description, long initValue)
          Create a mutable long integer counter
 MetricMutableGaugeInt newGauge(String name, String description, int initValue)
          Create a mutable integer gauge
 MetricMutableGaugeLong newGauge(String name, String description, long initValue)
          Create a mutable long integer gauge
 MetricMutableStat newStat(String name)
          Create a mutable metric with stats using the name only
 MetricMutableStat newStat(String name, String description, String sampleName, String valueName)
          Create a mutable metric with stats
 MetricMutableStat newStat(String name, String description, 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(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
 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

MetricsRegistry

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

Parameters:
name - of the record of the metrics

MetricsRegistry

public MetricsRegistry(String name,
                       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 MetricMutable get(String name)
Get a metric by name

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

newCounter

public 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 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 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 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 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 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 MetricMutableStat newStat(String name)
Create a mutable metric with stats using the name only

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

incr

public void incr(String name)
Increment a metric by name.

Parameters:
name - of the metric

incr

public void incr(String name,
                 MetricMutableFactory factory)
Increment a metric by name.

Parameters:
name - of the metric
factory - to lazily create the metric if not null

decr

public void decr(String name)
Decrement a metric by name.

Parameters:
name - of the metric

decr

public void decr(String name,
                 MetricMutableFactory factory)
Decrement a metric by name.

Parameters:
name - of the metric
factory - to lazily create the metric if not null

add

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

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

add

public void add(String name,
                long value,
                MetricMutableFactory factory)
Decrement a metric by name.

Parameters:
name - of the metric
value - of the snapshot to add
factory - to lazily create the metric if not null

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)

tags

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

Returns:
the tags set

metrics

public Set<Map.Entry<String,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.


Copyright © 2009 The Apache Software Foundation