java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.StreamHelper
Helper for the /streams page - shows active I2P streaming connections.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringOnly streams in this direction are shown, if set.private static final StringMarkup ending a table row.private static final StringMarkup starting a table row.private static final StringMarkup ending a table cell.private static final StringMarkup starting a table cell.Fields inherited from class HelperBase
_context, _log, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.protected LogThe log instance.protected WriterThe writer for output.static final StringChecked attribute for HTML checkboxes.static final StringProperty key for advanced mode.static final StringSelected attribute for HTML select options.Constructor Summary
ConstructorsConstructorDescriptionCreates a helper that renders active streaming connections to the /streams page.Method Summary
Modifier and TypeMethodDescription(package private) static doubleclosedStreamRateBps(double avgBytesPerConn, double avgLifetimeMs) Convert a byte-count stat's average value and average duration into a bytes/sec rate.(package private) static int[]Count open streaming sockets by direction, walking the tunnel controllers the same way the stream tables do.private static StringHTML-escape a string.private static StringformatKBps(double bytesPerSec) Format bytes/sec as KB/s or MB/s (decimal units, no HTML entities).private static StringformatSize(long bytes) Format bytes without space before unit: "0B", "1.23KiB".Gets the direction filter applied to the streams table.private doublegetStatAvg(String name, long period) Read a rate stat value from the stat manager, returning 0 if unavailable.private doublegetStatAvgDuration(String name, long period) Read the average event weight (duration in ms) from a rate stat, returning 0 if unavailable.private longgetStatCount(String name, long period) Read the last-event-count from a rate stat, returning 0 if unavailable.Render the streaming connections table(s).private voidrenderCombinedTable(Writer out, List<TunnelController> controllers, int inCount, long inSent, long inRecv, int outCount, long outSent, long outRecv) Render the combined table for the main page with inbound and outbound sections.private voidrenderStreamsHTML(Writer out) Writes the table of open streams.private voidrenderStreamStats(Writer out, int totalSockets) Render the streaming health ring dashboard.private voidrenderTable(Writer out, List<TunnelController> controllers, boolean inbound, String peerHeader, int count, long totalSent, long totalReceived) Render a simple filtered table (single section, no section header).private voidrenderTableSection(Writer out, List<TunnelController> controllers, boolean inbound, String peerHeader, int count, long totalSent, long totalReceived) Render one thead (section header + column headers) + tbody for a direction.voidSets the direction filter applied to the streams table.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, isAdvanced, ngettext, setContextId, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected StringgetChecked(String prop) Get the checked attribute for a boolean property.booleanCheck if advanced mode is enabled.Translate a string with plural forms (ngettext).voidsetContextId(String contextId) Configure this bean to query a particular router context.voidstoreWriter(Writer out) Store the writer for output.
Field Details
ROW_OPEN
ROW_CLOSE
TD_OPEN
TD_CLOSE
_direction
Only streams in this direction are shown, if set.
Constructor Details
StreamHelper
public StreamHelper()Creates a helper that renders active streaming connections to the /streams page.
Method Details
getDirection
Gets the direction filter applied to the streams table.- Returns:
- the configured direction, either "inbound" or "outbound", or empty when no filter is set and the combined table is rendered
setDirection
Sets the direction filter applied to the streams table.- Parameters:
d- the direction filter to apply: "inbound" or "outbound" restricts the table to one side, and null or empty renders the combined table
getStreamSummary
Render the streaming connections table(s).- Returns:
- the stream summary
getStatAvg
Read a rate stat value from the stat manager, returning 0 if unavailable.- Parameters:
name- the rate stat name, e.g. "stream.rtt"period- the rate period in ms, one of theRateConstantsvalues- Returns:
- the rate's average value, or 0 when the stat or period has no data
getStatCount
Read the last-event-count from a rate stat, returning 0 if unavailable.- Parameters:
name- the rate stat name, e.g. "stream.connectionCreated"period- the rate period in ms, one of theRateConstantsvalues- Returns:
- the event count of the most recent period, or 0 when the stat has no data
countStreams
Count open streaming sockets by direction, walking the tunnel controllers the same way the stream tables do. Used by the debug overview tile.- Parameters:
tcg- the controller group, or null before router init- Returns:
- {inbound, outbound} socket counts, or null if tcg is null
renderStreamsHTML
Writes the table of open streams.- Parameters:
out- where the table is written- Throws:
IOException- if the page cannot be written
getStatAvgDuration
Read the average event weight (duration in ms) from a rate stat, returning 0 if unavailable.- Parameters:
name- the rate stat name, e.g. "stream.con.lifetimeBytesSent"period- the rate period in ms, one of theRateConstantsvalues- Returns:
- the average event duration in ms, or 0 when the stat has no data
closedStreamRateBps
static double closedStreamRateBps(double avgBytesPerConn, double avgLifetimeMs) Convert a byte-count stat's average value and average duration into a bytes/sec rate. The stream lifetime byte stats record each closed connection's total bytes weighted by its lifetime, so avgValue/avgDuration is the mean throughput of the streams that closed in the window. Streams that never close report nothing.- Parameters:
avgBytesPerConn- average lifetime bytes per closed connectionavgLifetimeMs- average closed-connection lifetime in ms- Returns:
- the average rate in bytes/s, 0 when either input is missing
renderStreamStats
Render the streaming health ring dashboard.- Parameters:
out- the writer the dashboard HTML is written tototalSockets- the number of open streaming sockets, shown in the Active ring; 0 renders that ring with no data- Throws:
IOException- if writing to the writer fails
renderCombinedTable
private void renderCombinedTable(Writer out, List<TunnelController> controllers, int inCount, long inSent, long inRecv, int outCount, long outSent, long outRecv) throws IOException Render the combined table for the main page with inbound and outbound sections.- Parameters:
out- the writer the HTML is written tocontrollers- the tunnel controllers scanned for open socketsinCount- the number of inbound sockets, shown in the section headerinSent- total bytes sent on inbound sockets, shown in the headerinRecv- total bytes received on inbound sockets, shown in the headeroutCount- the number of outbound sockets, shown in the section headeroutSent- total bytes sent on outbound sockets, shown in the headeroutRecv- total bytes received on outbound sockets, shown in the header- Throws:
IOException- if writing to the writer fails
renderTableSection
private void renderTableSection(Writer out, List<TunnelController> controllers, boolean inbound, String peerHeader, int count, long totalSent, long totalReceived) throws IOException Render one thead (section header + column headers) + tbody for a direction.- Parameters:
out- the writer the HTML is written tocontrollers- the tunnel controllers scanned for open socketsinbound- true renders the inbound (server) section, false the outbound onepeerHeader- the header text for the peer column, "Peer" or "Target"count- the number of sockets in this direction, shown in the headertotalSent- total bytes sent in this direction, shown in the headertotalReceived- total bytes received in this direction, shown in the header- Throws:
IOException- if writing to the writer fails
renderTable
private void renderTable(Writer out, List<TunnelController> controllers, boolean inbound, String peerHeader, int count, long totalSent, long totalReceived) throws IOException Render a simple filtered table (single section, no section header).- Parameters:
out- the writer the HTML is written tocontrollers- the tunnel controllers scanned for open socketsinbound- true renders the inbound (server) rows, false the outbound onespeerHeader- the header text for the peer column, "Peer" or "Target"count- the number of sockets in this direction, shown in the headertotalSent- total bytes sent in this direction, shown in the headertotalReceived- total bytes received in this direction, shown in the header- Throws:
IOException- if writing to the writer fails
formatKBps
Format bytes/sec as KB/s or MB/s (decimal units, no HTML entities).- Parameters:
bytesPerSec- the rate to format, in bytes per second- Returns:
- the formatted rate with one decimal for KB/s and MB/s, whole B/s below 1000
formatSize
Format bytes without space before unit: "0B", "1.23KiB".- Parameters:
bytes- the byte count to format- Returns:
- the size with a binary unit suffix and no space, e.g. "1.23KiB"
esc