java.lang.Object
net.i2p.router.web.helpers.StatsGenerator

public class StatsGeneratorextends Object
Dump the stats to the web admin interface.
  • Field Details

  • Constructor Details

    • StatsGenerator

      public StatsGenerator(RouterContext context)
      Hold the router context whose StatManager supplies the stats.
      Parameters:
      context - the router context whose StatManager supplies the stats
  • Method Details

    • generateCSV

      public void generateCSV(Writer out, String filter) throws IOException
      Generate CSV export of all stats (optionally filtered by name).
      Parameters:
      out - where the CSV text is written and flushed
      filter - optional case-insensitive stat name substring, null or empty for every stat
      Throws:
      IOException - if the writer fails partway through the export
    • generateStatsPage

      public void generateStatsPage(Writer out, boolean showAll, String filter) throws IOException
      Render the stats page as HTML.
      Parameters:
      out - where the HTML is written
      showAll - true to include the saturation and per-period extremes that are hidden in the default view
      filter - optional stat name substring filter (case-insensitive), null for all
      Throws:
      IOException - if the writer fails partway through the page
    • renderFrequency

      private void renderFrequency(String name, StringBuilder buf)
      Writes one frequency statistic.
      Parameters:
      name - the stat's name
      buf - where the text is written
    • renderRate

      private void renderRate(String name, StringBuilder buf, boolean showAll)
      Writes one rate statistic.
      Parameters:
      name - the stat's name
      buf - where the text is written
      showAll - true to write every time period
    • renderPeriod

      private static void renderPeriod(StringBuilder buf, long period, String name)
      Writes one period column of a rate table.
      Parameters:
      buf - where the text is written
      period - the period length, in ms
      name - the stat's name
    • downloadName

      static String downloadName(String name)
      The download filename offered for a stat's XML export.

      Stat names carry dots, spaces and, for a per-tunnel stat, brackets around a user-supplied nickname, all of which landed in the download attribute verbatim, so a nickname holding a double quote closed the attribute early. Dots and spaces become underscores and anything HTML-significant is escaped; a plain name such as bw.sendRate still reads graphdata_bw_sendRate.xml.

      Parameters:
      name - the stat name as registered
      Returns:
      a filename safe inside a quoted HTML attribute
    • num

      private static final String num(double num)
      Formats a plain number.
      Parameters:
      num - the value to format
      Returns:
      the text to show
    • pct

      private static final String pct(double num)
      Formats a percentage.
      Parameters:
      num - the value to format
      Returns:
      the text to show
    • _t

      private String _t(String s)
      Translate a string.
      Parameters:
      s - the string to look up in the console bundle
      Returns:
      the translation, or s itself when there is none
    • _t

      private String _t(String s, Object o)
      Translate a string carrying one parameter.
      Parameters:
      s - the string to look up, with {0} where the parameter goes
      o - the parameter substituted for {0}, not itself translated
      Returns:
      the translated string with {0} replaced
    • ngettext

      private String ngettext(String s, String p, int n)
      Translate a string whose form depends on a count (ngettext).
      Parameters:
      s - the singular English text, also the lookup key
      p - the plural English text
      n - the count deciding which form is used
      Returns:
      the translated form for that count