java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
org.klomp.snark.BandwidthGraph
- All Implemented Interfaces:
Runnable
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
FieldsModifier and TypeFieldDescriptionstatic final intRing capacity: 240 samples = 4 hours at 60 s.static final longSample once per minute.static final longWindow covered by a full ring, in ms; older persisted samples are dropped.Fields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected net.i2p.util.SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Method Summary
Modifier and TypeMethodDescriptionstatic voiddatagramReceived(int bytes) Record datagram bytes received (DHT + UDP tracker listeners).static voiddatagramSent(int bytes) Record datagram bytes sent (DHT + UDP tracker funnel).static StringSerialize the ring oldest-first as "timestampSec,rxKB,txKB;...".static longThe current sample version: increments once per stored sample.static voidhttpTransferred(long txBytes, long rxBytes) Record an HTTP tracker/torrent fetch: approximate request size plus response size.static voidstart(SnarkManager manager) Start the sampler for this snark manager, loading prior history from the tmp-dir file when present.static voidstop()Stop the sampler and flush pending history.voidOne 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, toStringModifier and TypeMethodDescriptionbooleancancel()Cancel the timed event.voidforceReschedule(long timeoutMs) Always use the new time - ignores fuzz.voidreschedule(long timeoutMs) Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.voidreschedule(long timeoutMs, boolean useEarliestTime) May be called from within timeReached(), but schedule() is better there.voidrun()voidschedule(long timeoutMs) Schedule this event.voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.toString()Timer summary for log messages.
Field Details
SAMPLE_INTERVAL_MS
CAPACITY
public static final int CAPACITYRing capacity: 240 samples = 4 hours at 60 s.- See Also:
WINDOW_MS
public static final long WINDOW_MSWindow 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 zerorxBytes- the bytes received, added only when greater than zero
start
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
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:
timeReachedin classSimpleTimer2.TimedEvent