net.i2p.stat

## Class StatManager

- java.lang.Object
- - net.i2p.stat.StatManager

-     public class StatManager
      extends Object

  Coordinate the management of various frequencies and rates within I2P components, both allowing central update and retrieval, as well as distributed creation and use. This does not provide any persistence, but the data structures exposed can be read and updated to manage the complete state.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_STAT_FULL` default false

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StatManager(I2PAppContext context)` The stat manager should only be constructed and accessed through the application context.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRateData(String name, long data)` Update the given rate statistic, taking note that the given data point was received (and recalculating all rates).
    `void` | `addRateData(String name, long data, long eventDuration)` update the given rate statistic, taking note that the given data point was received (and recalculating all rates)
    `void` | `coalesceStats()`
    `void` | `createFrequencyStat(String name, String description, String group, long[] periods)` Create a new statistic to monitor the frequency of some event.
    `void` | `createRateStat(String name, String description, String group, long[] periods)` Create a new statistic to monitor the average value and confidence of some action.
    `void` | `createRequiredFrequencyStat(String name, String description, String group, long[] periods)` Create a new statistic to monitor the frequency of some event.
    `void` | `createRequiredRateStat(String name, String description, String group, long[] periods)` Create a new statistic to monitor the average value and confidence of some action.
    `FrequencyStat` | `getFrequency(String name)` Misnamed, as it returns a FrequencyStat, not a Frequency.
    `Set<String>` | `getFrequencyNames()` Get the names of all frequency statistics.
    `RateStat` | `getRate(String name)` Misnamed, as it returns a RateStat, not a Rate.
    `Set<String>` | `getRateNames()` Get the names of all rate statistics.
    `Map<String,SortedSet<String>>` | `getStatsByGroup()` Group name (untranslated String) to a SortedSet of untranslated stat names.
    `boolean` | `ignoreStat(String statName)` Save memory by not creating stats unless they are required for router operation.
    `boolean` | `isFrequency(String statName)` is the given stat a monitored frequency?
    `boolean` | `isRate(String statName)` is the given stat a monitored rate?
    `void` | `removeRateStat(String name)`
    `void` | `shutdown()` Shut down the statistics manager and clear all statistics.
    `void` | `store(OutputStream out, String prefix)` Serializes all Frequencies and Rates to the provided OutputStream
    `void` | `updateFrequency(String name)` update the given frequency statistic, taking note that an event occurred (and recalculating all frequencies)

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

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

- - ### Field Detail

    - #### PROP_STAT_FULL

          public static final String PROP_STAT_FULL

      default false
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StatManager

          public StatManager(I2PAppContext context)

      The stat manager should only be constructed and accessed through the application context. This constructor should only be used by the appropriate application context itself.

  - ### Method Detail

    - #### addRateData

          public void addRateData(String name,
                                  long data)

      Update the given rate statistic, taking note that the given data point was received (and recalculating all rates). Zero duration.

    - #### addRateData

          public void addRateData(String name,
                                  long data,
                                  long eventDuration)

      update the given rate statistic, taking note that the given data point was received (and recalculating all rates)

    - #### coalesceStats

          public void coalesceStats()

    - #### createFrequencyStat

          public void createFrequencyStat(String name,
                                          String description,
                                          String group,
                                          long[] periods)

      Create a new statistic to monitor the frequency of some event. The stat is ONLY created if the stat.full property is true or we are not in the router context.
      Parameters:
        `name` - unique name of the statistic
        `description` - simple description of the statistic
        `group` - used to group statistics together
        `periods` - array of period lengths (in milliseconds)

    - #### createRateStat

          public void createRateStat(String name,
                                     String description,
                                     String group,
                                     long[] periods)

      Create a new statistic to monitor the average value and confidence of some action. The stat is ONLY created if the stat.full property is true or we are not in the router context.
      Parameters:
        `name` - unique name of the statistic
        `description` - simple description of the statistic
        `group` - used to group statistics together
        `periods` - array of period lengths (in milliseconds)

    - #### createRequiredFrequencyStat

          public void createRequiredFrequencyStat(String name,
                                                  String description,
                                                  String group,
                                                  long[] periods)

      Create a new statistic to monitor the frequency of some event. The stat is always created, independent of the stat.full setting or context.
      Parameters:
        `name` - unique name of the statistic
        `description` - simple description of the statistic
        `group` - used to group statistics together
        `periods` - array of period lengths (in milliseconds)

    - #### createRequiredRateStat

          public void createRequiredRateStat(String name,
                                             String description,
                                             String group,
                                             long[] periods)

      Create a new statistic to monitor the average value and confidence of some action. The stat is always created, independent of the stat.full setting or context.
      Parameters:
        `name` - unique name of the statistic
        `description` - simple description of the statistic
        `group` - used to group statistics together
        `periods` - array of period lengths (in milliseconds)

    - #### getFrequency

          public FrequencyStat getFrequency(String name)

      Misnamed, as it returns a FrequencyStat, not a Frequency.

    - #### getFrequencyNames

          public Set<String> getFrequencyNames()

      Get the names of all frequency statistics.
      Returns:
        a copy of the frequency stat names

    - #### getRate

          public RateStat getRate(String name)

      Misnamed, as it returns a RateStat, not a Rate.

    - #### getRateNames

          public Set<String> getRateNames()

      Get the names of all rate statistics.
      Returns:
        a copy of the rate stat names

    - #### getStatsByGroup

          public Map<String,SortedSet<String>> getStatsByGroup()

      Group name (untranslated String) to a SortedSet of untranslated stat names. Map is unsorted.

    - #### ignoreStat

          public boolean ignoreStat(String statName)

      Save memory by not creating stats unless they are required for router operation. For backward compatibility of any external clients, always returns false if not in router context.
      Parameters:
        `statName` - ignored
      Returns:
        true if the stat should be ignored.

    - #### isFrequency

          public boolean isFrequency(String statName)

      is the given stat a monitored frequency?

    - #### isRate

          public boolean isRate(String statName)

      is the given stat a monitored rate?

    - #### removeRateStat

          public void removeRateStat(String name)

    - #### shutdown

          public void shutdown()

      Shut down the statistics manager and clear all statistics.

    - #### store

          public void store(OutputStream out,
                            String prefix)
                     throws IOException

      Serializes all Frequencies and Rates to the provided OutputStream
      Parameters:
        `out` - to write to
        `prefix` - to use when serializing
      Throws:
        `IOException` - if something goes wrong

    - #### updateFrequency

          public void updateFrequency(String name)

      update the given frequency statistic, taking note that an event occurred (and recalculating all frequencies)