MutableRollingAverages (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.metrics2.lib, class: MutableRollingAverages

Package org.apache.hadoop.metrics2.lib

# Class MutableRollingAverages

java.lang.Object
org.apache.hadoop.metrics2.lib.MutableMetric
org.apache.hadoop.metrics2.lib.MutableRollingAverages

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

@Public @Evolving public class MutableRollingAverages extends MutableMetric implements Closeable

This class maintains a group of rolling average metrics. It implements the algorithm of rolling average, i.e. a number of sliding windows are kept to roll over and evict old subsets of samples. Each window has a subset of samples in a stream, where sub-sum and sub-total are collected. All sub-sums and sub-totals in all windows will be aggregated to final-sum and final-total used to compute final average, which is called rolling average.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MutableRollingAverages(String metricValueName)`
  Constructor for `MutableRollingAverages`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(String name, long value)`
  `void`
  `close()`
  `void`
  `collectThreadLocalStates()`
  Collects states maintained in `ThreadLocal`, if any.
  `Map<String,Double>`
  `getStats(long minSamples)`
  Retrieve a map of metric name -> (aggregate).
  `void`
  `setRecordValidityMs(long value)`
  Use for test only.
  `void`
  `snapshot(MetricsRecordBuilder builder, boolean all)`
  Get a snapshot of the metric

  ### Methods inherited from class org.apache.hadoop.metrics2.lib.MutableMetric

  `changed, clearChanged, setChanged, snapshot`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MutableRollingAverages

    public MutableRollingAverages(String metricValueName)
    Constructor for `MutableRollingAverages`.
    Parameters:
      `metricValueName` - input metricValueName.

- ## Method Details

  - ### snapshot

    public void snapshot(MetricsRecordBuilder builder, boolean all)
    Description copied from class: `MutableMetric`
    Get a snapshot of the metric
    Specified by:
      `snapshot` in class `MutableMetric`
    Parameters:
      `builder` - the metrics record builder
      `all` - if true, snapshot unchanged metrics as well

  - ### collectThreadLocalStates

    public void collectThreadLocalStates()
    Collects states maintained in `ThreadLocal`, if any.

  - ### add

    public void add(String name, long value)
    Parameters:
      `name` - name of metric
      `value` - value of metric

  - ### close

    public void close() throws IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Throws:
      `IOException`

  - ### getStats

    public Map<String,Double> getStats(long minSamples)
    Retrieve a map of metric name -> (aggregate). Filter out entries that don't have at least minSamples.
    Parameters:
      `minSamples` - input minSamples.
    Returns:
      a map of peer DataNode Id to the average latency to that node seen over the measurement period.

  - ### setRecordValidityMs

    @VisibleForTesting public void setRecordValidityMs(long value)
    Use for test only.
    Parameters:
      `value` - input value.