java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.router.tasks.CoalesceStatsEvent
All Implemented Interfaces:
Runnable

public class CoalesceStatsEventextends SimpleTimer2.TimedEvent
Periodic statistics collection and aggregation system.

This event runs every minute to collect, aggregate, and coalesce router performance statistics. It gathers metrics from all major router components and updates the statistics framework for monitoring and analysis.

Statistics Collected:

  • Network metrics - peer counts, bandwidth usage
  • System resources - memory usage, CPU load, thread count
  • Tunnel performance - build success rates, participation
  • Router health - job queue lag, processing times
  • Communication system - send/receive rates, error counts

Features:

  • Automatic cache clearing when memory is low
  • Rate calculation and rolling averages
  • Performance trend monitoring
  • Data available via /stats.jsp and /graphs.jsp

This data is essential for router performance monitoring, troubleshooting, and capacity planning. The statistics are used by the router console to display real-time performance graphs and historical trends.

  • Field Details

    • _ctx

      private final RouterContext _ctx
      The router whose stats are coalesced.
    • _maxMemory

      private final long _maxMemory
      Heap the JVM will use, in bytes.
    • LOW_MEMORY_THRESHOLD

      private static final long LOW_MEMORY_THRESHOLD
      Free heap that counts as low: 5 MB.
      See Also:
    • _log

      private final Log _log
      Logger for this class.
    • _lastGcPauseTime

      private long _lastGcPauseTime
      Cumulative GC pause time, in ms, observed at the previous coalesce cycle, used to derive per-minute GC latency; -1 means uninitialized.
  • Constructor Details

    • CoalesceStatsEvent

      public CoalesceStatsEvent(RouterContext ctx)
      Create a new stats coalescence event. Initializes all required rate statistics for monitoring router performance.
      Parameters:
      ctx - the router context for accessing statistics manager
  • Method Details

    • timeReached

      public void timeReached()
      Collect and coalesce router statistics.

      This method is called periodically to gather various router metrics including network statistics, peer counts, memory usage, and tunnel performance. The collected data is used for monitoring and performance analysis.

      Statistics collected include:

      • Peer counts (known, active, fast, high capacity, etc.)
      • Bandwidth usage (send/receive rates)
      • Memory usage and CPU load
      • Tunnel performance metrics
      • Thread counts and system resources
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent
    • collectStats

      private void collectStats()
      Gather this cycle's statistics and coalesce them into the Rates.

      Called every Router.COALESCE_TIME by timeReached(), which guarantees the reschedule and contains any exception this throws, so nothing here needs its own try/catch.

    • _x

      private static final String _x(String s)
      Mark a string for extraction by xgettext and translation. Use this only in static initializers. It does not translate!
      Parameters:
      s - the literal string to mark for extraction
      Returns:
      the string unchanged, present only so xgettext can extract it
    • getCumulativeGcPauseTime

      private static long getCumulativeGcPauseTime()
      Cumulative GC pause time (ms) across all collectors since JVM start. Returns -1 if GC beans are unavailable.
      Returns:
      the cumulative gc pause time
    • getGcPauseTime

      private long getGcPauseTime()
      GC pause time (ms) elapsed since the previous coalesce cycle. Returns -1 on the first call (no baseline) or if GC data is unavailable.
      Returns:
      the gc pause time