All Implemented Interfaces:
Runnable

public class BandwidthGraphextends SimpleTimer2.TimedEvent
Self-contained bandwidth sampler for the snark screen log graph. Every SAMPLE_INTERVAL_MS, snapshots the cumulative traffic counters (peer wire rates summed over torrents, datagram counters fed by DatagramSender and the receive paths, HTTP tracker counters fed by I2PSnarkUtil) and stores per-interval byte totals in a fixed ring. Runs for the webapp's lifetime, independent of any browser being open, so the graph stays continuous. Flushes to the tmp dir every FLUSH_INTERVAL_MS so history survives webapp or router restarts; entries older than WINDOW_MS are dropped on load.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Ring capacity: 240 samples = 4 hours at 60 s.
    static final long
    Sample once per minute.
    static final long
    Window covered by a full ring, in ms; older persisted samples are dropped.

    Fields inherited from class SimpleTimer2.TimedEvent

    _state, DEFAULT_FUZZ
    Modifier and Type
    Field
    Description
    protected net.i2p.util.SimpleTimer2.TimedEventState
    State of the current event.
    protected static final int
    Default fuzz threshold in milliseconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    datagramReceived(int bytes)
    Record datagram bytes received (DHT + UDP tracker listeners).
    static void
    datagramSent(int bytes)
    Record datagram bytes sent (DHT + UDP tracker funnel).
    static String
    Serialize the ring oldest-first as "timestampSec,rxKB,txKB;...".
    static long
    The current sample version: increments once per stored sample.
    static void
    httpTransferred(long txBytes, long rxBytes)
    Record an HTTP tracker/torrent fetch: approximate request size plus response size.
    static void
    Start the sampler for this snark manager, loading prior history from the tmp-dir file when present.
    static void
    Stop the sampler and flush pending history.
    void
    One sampling pass: derive interval bytes from counter deltas plus current peer-wire rates, append to the ring, and flush periodically.

    Methods inherited from class SimpleTimer2.TimedEvent

    cancel, forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPool, toString
    Modifier and Type
    Method
    Description
    boolean
    Cancel the timed event.
    void
    forceReschedule(long timeoutMs)
    Always use the new time - ignores fuzz.
    void
    reschedule(long timeoutMs)
    Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.
    void
    reschedule(long timeoutMs, boolean useEarliestTime)
    May be called from within timeReached(), but schedule() is better there.
    void
    run()
    void
    schedule(long timeoutMs)
    Schedule this event.
    void
    setFuzz(int fuzz)
    Reschedule threshold in ms.
    void
    Timer pool for this event.
    Timer summary for log messages.

    Methods inherited from class Object

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

    • SAMPLE_INTERVAL_MS

      public static final long SAMPLE_INTERVAL_MS
      Sample once per minute.
      See Also:
    • CAPACITY

      public static final int CAPACITY
      Ring capacity: 240 samples = 4 hours at 60 s.
      See Also:
    • WINDOW_MS

      public static final long WINDOW_MS
      Window covered by a full ring, in ms; older persisted samples are dropped.
      See Also:
  • Method Details

    • datagramSent

      public static void datagramSent(int bytes)
      Record datagram bytes sent (DHT + UDP tracker funnel).
      Parameters:
      bytes - the datagram byte count to add to the cumulative sent total
    • datagramReceived

      public static void datagramReceived(int bytes)
      Record datagram bytes received (DHT + UDP tracker listeners).
      Parameters:
      bytes - the datagram byte count to add to the cumulative received total
    • httpTransferred

      public static void httpTransferred(long txBytes, long rxBytes)
      Record an HTTP tracker/torrent fetch: approximate request size plus response size.
      Parameters:
      txBytes - the bytes sent, added only when greater than zero
      rxBytes - the bytes received, added only when greater than zero
    • start

      public static void start(SnarkManager manager)
      Start the sampler for this snark manager, loading prior history from the tmp-dir file when present. Subsequent calls are no-ops.
      Parameters:
      manager - the manager whose torrent transfers the sampler records
    • stop

      public static void stop()
      Stop the sampler and flush pending history. Safe to call repeatedly.
    • getVersion

      public static long getVersion()
      The current sample version: increments once per stored sample. Clients use it to detect new data without parsing the samples themselves.
      Returns:
      monotonically increasing sample counter
    • getSamples

      public static String getSamples()
      Serialize the ring oldest-first as "timestampSec,rxKB,txKB;...". Values are KB (bytes/1024 rounded) to keep the wire format compact.
      Returns:
      compact CSV of every stored sample, empty string when none
    • timeReached

      public void timeReached()
      One sampling pass: derive interval bytes from counter deltas plus current peer-wire rates, append to the ring, and flush periodically.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent