java.lang.Object
net.i2p.router.StatisticsManager

public class StatisticsManagerextends Object
Collects and publishes router performance statistics to the network database. Provides bandwidth, tunnel, and peer metrics for router capability advertising.
  • Field Details

    • _log

      private final Log _log
      The log for the statistics.
    • _context

      private final RouterContext _context
      The router context.
    • _networkID

      private final String _networkID
      The network id to report.
    • PROP_PUBLISH_RANKINGS

      public static final String PROP_PUBLISH_RANKINGS
      Config property controlling whether to publish peer rankings.
      See Also:
    • RANDOM_INCLUDE_STATS

      private static final int RANDOM_INCLUDE_STATS
      Enhance anonymity by only including build stats one out of this many times.
      See Also:
    • SIMPLE_STATS

      private static final boolean SIMPLE_STATS
      Whether the simple stats format is used.
      See Also:
    • _fmt

      private final DecimalFormat _fmt
      The number format of the stats.
    • _pct

      private final DecimalFormat _pct
      The percent format of the stats.
    • tunnelStats

      private static final String[] tunnelStats
      The names of the tunnel build stats.
  • Constructor Details

    • StatisticsManager

      public StatisticsManager(RouterContext context)
      Captures the router context and prepares the number and percentage formatters.
      Parameters:
      context - the router context supplying the identity, rates and config
  • Method Details

    • publishStatistics

      public Properties publishStatistics()
      Retrieve a snapshot of the statistics that should be published.

      This includes all standard options (as of 0.9.24, network ID and caps).

      Returns:
      the statistics as an unsigned Properties set
    • publishStatistics

      public Properties publishStatistics(Hash h)
      Retrieve a snapshot of the statistics that should be published.

      This includes all standard options (as of 0.9.24, network ID and caps).

      Parameters:
      h - current router hash, non-null
      Returns:
      the statistics as an unsigned Properties set
    • includeRate

      private void includeRate(String rateName, Properties stats, long[] selectedPeriods, boolean fudgeQuantity)
      Include a named rate's data in the published stats.
      Parameters:
      rateName - the rate to include
      stats - the properties to add to
      selectedPeriods - the periods to include, or null for all
      fudgeQuantity - the data being published in this stat is too sensitive to, uh publish, so we're kludge the quantity (allowing the fairly safe publication of the average values
    • renderRate

      private String renderRate(Rate rate, boolean fudgeQuantity)
      Simple format, only what stats.i2p needs:
       average
      

      Previous format:

       avg;extreme avg;pct of lifetime avg;
       if lifetime total event time greater than zero:
            lastEventSaturation;lastSaturationLimit;extremeEventSaturation;extremeSaturationLimit;
       event count;
       if number of periods greater than zero:
            avg freq;exteremeEventCount;lifetimeEventCount;
      
      Parameters:
      rate - the rate to render
      fudgeQuantity - true to replace the event counts with the placeholder 555, hiding absolute quantities
      Returns:
      the semicolon-separated statistics fields
    • includeTunnelRates

      private void includeTunnelRates(String tunnelType, Properties stats, long selectedPeriod)
      Add tunnel build rates with some mods to hide absolute quantities In particular, report counts normalized to 100 (i.e. a percentage).
      Parameters:
      tunnelType - the tunnel type in the rate name, e.g. Exploratory
      stats - the properties the rendered rates are stored in
      selectedPeriod - the rate period in milliseconds to report
    • renderRate

      private String renderRate(Rate rate, double fudgeQuantity)
      Simple format, only what stats.i2p needs:
       0;0;0;percent or event count
      

      Previous format: see above

      Parameters:
      rate - the rate to render
      fudgeQuantity - the value rendered in place of the event count, normally the count normalized to 100
      Returns:
      the semicolon-separated statistics fields
    • getPeriod

      private static String getPeriod(Rate rate)
      The period label of a rate.
      Parameters:
      rate - the rate to label
      Returns:
      the formatted period
    • num

      private final String num(double num)
      Formats a number for the stats.
      Parameters:
      num - the number to format
      Returns:
      the formatted text
    • pct

      private final String pct(double num)
      Formats a percentage for the stats.
      Parameters:
      num - the percentage to format
      Returns:
      the formatted text
    • renderStatusHTML

      public void renderStatusHTML(Writer out)
      Render the status in HTML. Intentionally a no-op.
      Parameters:
      out - accepted and left untouched, since this implementation renders nothing