Class MetricsRegistry

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

@Public @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 Details

    • 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 Details

    • 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
    • newGauge

      public org.apache.hadoop.metrics2.lib.MutableGaugeFloat newGauge(String name, String desc, float iVal)
      Create a mutable float gauge
      Parameters:
      name - of the metric
      desc - metric description
      iVal - initial value
      Returns:
      a new gauge object
    • newGauge

      public org.apache.hadoop.metrics2.lib.MutableGaugeFloat newGauge(MetricsInfo info, float iVal)
      Create a mutable float 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
      Throws:
      MetricsException - if interval is not a positive integer
    • newInverseQuantiles

      public MutableQuantiles newInverseQuantiles(String name, String desc, String sampleName, String valueName, int interval)
      Create a mutable inverse metric that estimates inverse 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., "Rate")
      interval - rollover interval of estimator in seconds
      Returns:
      a new inverse quantile estimator object
      Throws:
      MetricsException - if interval is not a positive integer
    • 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
    • newRate

      @Private public MutableRate newRate(String name, String desc, boolean extended, boolean returnExisting)
    • newRatesWithAggregation

      public MutableRatesWithAggregation newRatesWithAggregation(String name)
    • newMutableRollingAverages

      public MutableRollingAverages newMutableRollingAverages(String name, String valueName)
    • 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