java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.HealthHelper
Helper for the /health page - renders router health rings using
RingRenderer for a quick visual overview.Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classBaseline-vs-current evaluation result for a single stat.Field Summary
Fields inherited from class HelperBase
_context, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.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 bound to the currently selected router context.Method Summary
Modifier and TypeMethodDescription(package private) static doublebwUtilization(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 StringformatBW(double bytes) Format bytes as B/s, KB/s or MB/s.private static StringformatCompactDuration(long ms) Format a duration compactly: 230s, 24m, 3h, 2d, 1mo, plain text with no HTML.private static StringformatMB(double bytes) Format a byte count as whole megabytes.private HealthHelper.AnomalygetAnomaly(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 doublegetStatAvg(String name) Return a rate stat's current value: the current partial period average if available, else the last full period.private longgetStatCount(String name) Return a rate stat's event count from the narrowest 1-minute window only, for throughput calculations.private double[]getStatHistory(String name) Return the last 5 history data points for a stat, trying wider windows if needed.Render the transport and connectivity rings as HTML.booleanWhether 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 voidrenderFFSection(Writer out) 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 voidrenderHealth(Writer out) Legacy: renders all rings in a single div.private voidSection 3 – Network & Participation (8 rings) Peers: Active Peers, Known Peers | Role: Clients, Transit | Health: Build Success, NetDB, Uptime | Security: Banned.private voidrenderPerfSection(Writer out) Section 1 – Performance & Load (8 rings) Resource: Bandwidth, CPU, Memory | Latency: BW Delay, Job Lag, Msg Lag | Job: Job Queue, Threads.private voidSection 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, 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
_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
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
Render the performance and load rings as HTML.- Returns:
- the rendered HTML, or an empty string if rendering failed
getTransportRings
Render the transport and connectivity rings as HTML.- Returns:
- the rendered HTML, or an empty string if rendering failed
getNetworkRings
Render the network and participation rings as HTML.- Returns:
- the rendered HTML, or an empty string if rendering failed
getFFRings
Render the floodfill and NetDB rings as HTML.- Returns:
- the rendered HTML, or an empty string if rendering failed
getStatAvg
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
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
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
greenThresholdthe 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
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
Legacy: renders all rings in a single div. Kept for backward compat withgetHealthContent()/ storeWriter path.- Parameters:
out- the writer receiving the ring sections- Throws:
IOException- if writing the rendered sections fails
renderPerfSection
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
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
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
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
Build a details array from a base description plus an optional anomaly detail line.- Parameters:
desc- the base tooltip descriptionanomalyDetail- 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/srecvBps- current receive rate in bytes/sinLimit- inbound cap in bytes/s, 0 for unlimitedoutLimit- 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 nullden- 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
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
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
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