org.apache.hadoop.metrics2.lib

## Class MutableStat

- java.lang.Object
- - org.apache.hadoop.metrics2.lib.MutableMetric
  - - org.apache.hadoop.metrics2.lib.MutableStat

- Direct Known Subclasses:
    MutableRate

      @InterfaceAudience.Public
       @InterfaceStability.Evolving
      public class MutableStat
      extends MutableMetric

  A mutable metric with stats. Useful for keeping throughput/latency stats.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MutableStat(String name, String description, String sampleName, String valueName)` Construct a snapshot stat metric with extended stat off by default
    `MutableStat(String name, String description, String sampleName, String valueName, boolean extended)` Construct a sample statistics metric

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(long value)` Add a snapshot to the metric.
    `void` | `add(long numSamples, long sum)` Add a number of samples and their sum to the running stat Note that although use of this method will preserve accurate mean values, large values for numSamples may result in inaccurate variance values due to the use of a single step of the Welford method for variance calculation.
    `long` | `getSnapshotTimeStamp()` Return the SampleStat snapshot timestamp
    `org.apache.hadoop.metrics2.util.SampleStat` | `lastStat()` Return a SampleStat object that supports calls like StdDev and Mean.
    `void` | `resetMinMax()` Reset the all time min max of the metric
    `void` | `setExtended(boolean extended)` Set whether to display the extended stats (stdev, min/max etc.) or not
    `void` | `setUpdateTimeStamp(boolean updateTimeStamp)` Set whether to update the snapshot time or not.
    `void` | `snapshot(MetricsRecordBuilder builder, boolean all)` Get a snapshot of the metric
    `String` | `toString()`

    - ### 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, wait, wait, wait`

- - ### Constructor Detail

    - #### MutableStat

          public MutableStat(String name,
                             String description,
                             String sampleName,
                             String valueName,
                             boolean extended)

      Construct a sample statistics metric
      Parameters:
        `name` - of the metric
        `description` - of the metric
        `sampleName` - of the metric (e.g. "Ops")
        `valueName` - of the metric (e.g. "Time", "Latency")
        `extended` - create extended stats (stdev, min/max etc.) by default.

    - #### MutableStat

          public MutableStat(String name,
                             String description,
                             String sampleName,
                             String valueName)

      Construct a snapshot stat metric with extended stat off by default
      Parameters:
        `name` - of the metric
        `description` - of the metric
        `sampleName` - of the metric (e.g. "Ops")
        `valueName` - of the metric (e.g. "Time", "Latency")

  - ### Method Detail

    - #### setExtended

          public void setExtended(boolean extended)

      Set whether to display the extended stats (stdev, min/max etc.) or not
      Parameters:
        `extended` - enable/disable displaying extended stats

    - #### setUpdateTimeStamp

          public void setUpdateTimeStamp(boolean updateTimeStamp)

      Set whether to update the snapshot time or not.
      Parameters:
        `updateTimeStamp` - enable update stats snapshot timestamp

    - #### add

          public void add(long numSamples,
                          long sum)

      Add a number of samples and their sum to the running stat Note that although use of this method will preserve accurate mean values, large values for numSamples may result in inaccurate variance values due to the use of a single step of the Welford method for variance calculation.
      Parameters:
        `numSamples` - number of samples
        `sum` - of the samples

    - #### add

          public void add(long value)

      Add a snapshot to the metric.
      Parameters:
        `value` - of the metric

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

    - #### lastStat

          public org.apache.hadoop.metrics2.util.SampleStat lastStat()

      Return a SampleStat object that supports calls like StdDev and Mean.
      Returns:
        SampleStat

    - #### resetMinMax

          public void resetMinMax()

      Reset the all time min max of the metric

    - #### getSnapshotTimeStamp

          public long getSnapshotTimeStamp()

      Return the SampleStat snapshot timestamp

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2022 Apache Software Foundation. All rights reserved.