java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.HealthHelper

public class HealthHelperextends HelperBase
Helper for the /health page - renders router health rings using RingRenderer for a quick visual overview.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Baseline-vs-current evaluation result for a single stat.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Log
    Logger for this class.

    Fields inherited from class HelperBase

    _context, _out, CHECKED, PROP_ADVANCED, SELECTED
    Modifier and Type
    Field
    Description
    protected RouterContext
    The router context.
    protected Writer
    The writer for output.
    static final String
    Checked attribute for HTML checkboxes.
    static final String
    Property key for advanced mode.
    static final String
    Selected attribute for HTML select options.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a helper bound to the currently selected router context.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static double
    bwUtilization(double sendBps, double recvBps, int inLimit, int outLimit)
    Bandwidth utilization: the worst of the two directions, each measured against its own cap, so a saturated outbound link reads 100% even with an idle inbound one.
    private int[]
    Count active I2P streaming connections across all tunnel controllers.
    private static String
    formatBW(double bytes)
    Format bytes as B/s, KB/s or MB/s.
    private static String
    Format a duration compactly: 230s, 24m, 3h, 2d, 1mo, plain text with no HTML.
    private static String
    formatMB(double bytes)
    Format a byte count as whole megabytes.
    getAnomaly(String name, double greenThreshold)
    Evaluate a stat against the router's own baseline (10m and 1h averages).
    Render the floodfill and NetDB rings as HTML.
    Render every health ring - performance, transport, network and, on a floodfill, floodfill - as one block of HTML.
    Render the network and participation rings as HTML.
    Render the performance and load rings as HTML.
    private double
    Return a rate stat's current value: the current partial period average if available, else the last full period.
    private long
    Return a rate stat's event count from the narrowest 1-minute window only, for throughput calculations.
    private double[]
    Return the last 5 history data points for a stat, trying wider windows if needed.
    Render the transport and connectivity rings as HTML.
    boolean
    Whether this router is a floodfill with floodfill enabled.
    (package private) static double[]
    ratioHistory(double[] num, double[] den)
    Element-wise ratio of two history arrays, NaN where the denominator is missing or non-positive, so the sparkline plots the same quantity the ring shows.
    private void
    Section 4 – Floodfill / NetDB (8 rings, shown when floodfill enabled) Capacity: LeaseSets | Perf: Cache Hit, Flood Verify, NetDB ACK | Throughput: Lookups/s, Requests/s, Stores/s | Errors: LS Timeout.
    private void
    Legacy: renders all rings in a single div.
    private void
    Section 3 – Network & Participation (8 rings) Peers: Active Peers, Known Peers | Role: Clients, Transit | Health: Build Success, NetDB, Uptime | Security: Banned.
    private void
    Section 1 – Performance & Load (8 rings) Resource: Bandwidth, CPU, Memory | Latency: BW Delay, Job Lag, Msg Lag | Job: Job Queue, Threads.
    private void
    Section 2 – Transport & Connectivity (8 rings) NTCP: NTCP Estab | SSU: SSU Estab, SSU RTO | Throughput: Conns/s, Msgs/s | Quality: RTT, Timeout%, Tunnel Build.
    private static String[]
    withDetail(String desc, String anomalyDetail)
    Build a details array from a base description plus an optional anomaly detail line.

    Methods inherited from class HelperBase

    _t, _t, _t, _x, getChecked, isAdvanced, ngettext, setContextId, storeWriter
    Modifier and Type
    Method
    Description
    Translate a string.
    _t(String s, Object o)
    Translate a string with a parameter.
    _t(String s, Object o, Object o2)
    Translate a string with two parameters.
    static String
    Mark a string for extraction by xgettext and translation.
    protected String
    Get the checked attribute for a boolean property.
    boolean
    Check if advanced mode is enabled.
    ngettext(String s, String p, int n)
    Translate a string with plural forms (ngettext).
    void
    setContextId(String contextId)
    Configure this bean to query a particular router context.
    void
    Store the writer for output.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _log

      private Log _log
      Logger for this class.
  • Constructor Details

    • HealthHelper

      public HealthHelper()
      Creates a helper bound to the currently selected router context.
  • Method Details

    • isFloodfill

      public boolean isFloodfill()
      Whether this router is a floodfill with floodfill enabled.
      Returns:
      true if the network database is a floodfill that is currently publishing, false if there is no context or it is not a floodfill
    • getHealthContent

      public String getHealthContent()
      Render every health ring - performance, transport, network and, on a floodfill, floodfill - as one block of HTML.
      Returns:
      the rendered HTML, or an empty string if the page has a writer to write into or if rendering failed
    • getPerfRings

      public String getPerfRings()
      Render the performance and load rings as HTML.
      Returns:
      the rendered HTML, or an empty string if rendering failed
    • getTransportRings

      public String getTransportRings()
      Render the transport and connectivity rings as HTML.
      Returns:
      the rendered HTML, or an empty string if rendering failed
    • getNetworkRings

      public String getNetworkRings()
      Render the network and participation rings as HTML.
      Returns:
      the rendered HTML, or an empty string if rendering failed
    • getFFRings

      public String getFFRings()
      Render the floodfill and NetDB rings as HTML.
      Returns:
      the rendered HTML, or an empty string if rendering failed
    • getStatAvg

      private double getStatAvg(String name)
      Return a rate stat's current value: the current partial period average if available, else the last full period.
      Parameters:
      name - the RateStat name, e.g. "udp.avgRTO"
      Returns:
      the most recent finite positive average from the 1m, 10m, 1h or lifetime windows, or 0 if the stat is unknown or has no usable value
    • getStatCount

      private long getStatCount(String name)
      Return a rate stat's event count from the narrowest 1-minute window only, for throughput calculations.
      Parameters:
      name - the RateStat name, e.g. "transport.messagesDelivered"
      Returns:
      the event count of the last complete 1-minute period, or 0 if the stat or its 1-minute window is unavailable
    • getAnomaly

      private HealthHelper.Anomaly getAnomaly(String name, double greenThreshold)
      Evaluate a stat against the router's own baseline (10m and 1h averages). A value near the router's normal range is green. Progressively larger deviations go yellow then red. When no baseline can be formed yet the result is "gray" (collecting) with a null detail.

      When the current value is at or below greenThreshold the result is unconditionally green — the absolute value is so small it cannot reasonably be called a regression even if the baseline is even smaller.

      Parameters:
      name - stat name (e.g. "udp.avgRTO")
      greenThreshold - absolute value below which the result is always green (0 to disable)
      Returns:
      anomaly result with color class and a human-readable detail line
    • getStatHistory

      private double[] getStatHistory(String name)
      Return the last 5 history data points for a stat, trying wider windows if needed.
      Parameters:
      name - the RateStat name, e.g. "bw.sendBps"
      Returns:
      the 5 most recent values from the first window (1m, 10m, 1h) that holds a non-NaN value, or null if the stat has no usable data
    • renderHealth

      private void renderHealth(Writer out) throws IOException
      Legacy: renders all rings in a single div. Kept for backward compat with getHealthContent() / storeWriter path.
      Parameters:
      out - the writer receiving the ring sections
      Throws:
      IOException - if writing the rendered sections fails
    • renderPerfSection

      private void renderPerfSection(Writer out) throws IOException
      Section 1 – Performance & Load (8 rings) Resource: Bandwidth, CPU, Memory | Latency: BW Delay, Job Lag, Msg Lag | Job: Job Queue, Threads.
      Parameters:
      out - the writer receiving the ring cells
      Throws:
      IOException - if writing the rendered section fails
    • renderTransportSection

      private void renderTransportSection(Writer out) throws IOException
      Section 2 – Transport & Connectivity (8 rings) NTCP: NTCP Estab | SSU: SSU Estab, SSU RTO | Throughput: Conns/s, Msgs/s | Quality: RTT, Timeout%, Tunnel Build.
      Parameters:
      out - the writer receiving the ring cells
      Throws:
      IOException - if writing the rendered section fails
    • renderNetworkSection

      private void renderNetworkSection(Writer out) throws IOException
      Section 3 – Network & Participation (8 rings) Peers: Active Peers, Known Peers | Role: Clients, Transit | Health: Build Success, NetDB, Uptime | Security: Banned.
      Parameters:
      out - the writer receiving the ring cells
      Throws:
      IOException - if writing the rendered section fails
    • renderFFSection

      private void renderFFSection(Writer out) throws IOException
      Section 4 – Floodfill / NetDB (8 rings, shown when floodfill enabled) Capacity: LeaseSets | Perf: Cache Hit, Flood Verify, NetDB ACK | Throughput: Lookups/s, Requests/s, Stores/s | Errors: LS Timeout.
      Parameters:
      out - the writer receiving the ring cells
      Throws:
      IOException - if writing the rendered section fails
    • countActiveStreams

      private int[] countActiveStreams()
      Count active I2P streaming connections across all tunnel controllers.
      Returns:
      a two-element array, open sockets in server (inbound) tunnels at index 0 and client (outbound) sockets at index 1; zeros if there are no controllers or tasks
    • withDetail

      private static String[] withDetail(String desc, String anomalyDetail)
      Build a details array from a base description plus an optional anomaly detail line.
      Parameters:
      desc - the base tooltip description
      anomalyDetail - the anomaly evaluation detail to append, null if none
      Returns:
      a one- or two-element tooltip array
    • bwUtilization

      static double bwUtilization(double sendBps, double recvBps, int inLimit, int outLimit)
      Bandwidth utilization: the worst of the two directions, each measured against its own cap, so a saturated outbound link reads 100% even with an idle inbound one. A direction with a 0 cap (unlimited) contributes 0.
      Parameters:
      sendBps - current send rate in bytes/s
      recvBps - current receive rate in bytes/s
      inLimit - inbound cap in bytes/s, 0 for unlimited
      outLimit - outbound cap in bytes/s, 0 for unlimited
      Returns:
      utilization 0.0-1.0+, may exceed 1.0 when over cap
    • ratioHistory

      static double[] ratioHistory(double[] num, double[] den)
      Element-wise ratio of two history arrays, NaN where the denominator is missing or non-positive, so the sparkline plots the same quantity the ring shows.
      Parameters:
      num - numerator history (e.g. matched lookups), may be null
      den - denominator history (e.g. handled lookups), may be null
      Returns:
      the ratio history, or null if either input is null or the lengths differ
    • formatMB

      private static String formatMB(double bytes)
      Format a byte count as whole megabytes.
      Parameters:
      bytes - the byte count, e.g. a JVM memory size
      Returns:
      the count truncated to whole megabytes with a " MB" suffix
    • formatCompactDuration

      private static String formatCompactDuration(long ms)
      Format a duration compactly: 230s, 24m, 3h, 2d, 1mo, plain text with no HTML.
      Parameters:
      ms - the duration in milliseconds
      Returns:
      the duration in whole units: seconds under a minute, minutes under an hour, then hours and minutes, days and hours, or months and days
    • formatBW

      private static String formatBW(double bytes)
      Format bytes as B/s, KB/s or MB/s.
      Parameters:
      bytes - the rate in bytes per second
      Returns:
      the rate with a unit chosen by magnitude: B/s under 1000, KB/s up to 999999, MB/s from 1000000