Stateless across requests except for per-request form state set via the setXxx() accessors; preferences are read from context properties.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classOrders graphs for display: "Router" group first, then remaining groups alphabetically, then by stat name and period.Nested classes/interfaces inherited from class FormHandler
FormHandler.MessageModifier and TypeClassDescriptionstatic classMessage class to encapsulate the message text and the canClose flag.Field Summary
FieldsModifier and TypeFieldDescriptionprivate intWhich of the two stat values to graph, -1 for both.private booleanWhether in and out rates share one line.private booleanWhether the area under the line is filled.private booleanWhether the graph line glows.private booleanWhether the legend is hidden.private booleanWhether restart markers are hidden.private booleanWhether the graph line is smoothed.private intGraph height in pixels.private booleanWhether this graph hides its legend.private intNumber of stat periods shown on the graph.private booleanWhether the settings are saved to the config.private intSeconds between graph refreshes.private booleanWhether event markers are drawn.private StringThe stat name being graphed.private booleanWhether graph times are shown in UTC.private intGraph width in pixels.private static final StringEscaped ampersand reused in the graph links.private static final booleanThe legend is shown by default.private static final booleanRestart markers are shown by default.private static final intDefault number of stat periods shown.private static final intDefault refresh delay, in seconds.private static final StringLink prefix to the graph page.private static final StringQuery parameter for the graph height.private static final char[]Hex digits for the percent-escapes urlStatName() emits.private static final StringQuery parameter for the legend.private static final StringQuery parameter for the restart markers.private static final intLargest period count accepted.private static final intSmallest period count accepted.private static final intSmallest refresh delay accepted, in seconds.private static final intSmallest graph width accepted.private static final intSmallest graph height accepted.private static final StringQuery parameter for the period count.private static final StringConfig key for combining the rates.private static final StringConfig key for showing event markers.private static final StringConfig key for area filling.private static final StringConfig key for the glow effect.private static final StringConfig key for hiding the legend.private static final StringConfig key for hiding restart markers.private static final StringConfig key for the period count.private static final StringConfig key for the refresh delay.private static final StringConfig key for line smoothing.private static final StringConfig key for UTC graph times.private static final StringConfig key for the graph width.private static final StringConfig key for the graph height.private static final StringQuery parameter for the event markers.private static final StringLink prefix to the stat detail page.private static final StringQuery parameter for the graph end time.private static final int[]Period lengths offered on the graph page.private static final StringQuery parameter for the graph width.Fields inherited from class FormHandler
_action, _context, _log, _method, _out, _requestWrapper, _session, _settingsModifier and TypeFieldDescriptionprotected StringForm action.protected RouterContextRouter context.protected LogClass logger.protected StringRequest method.protected WriterOutput writer.protected RequestWrapperOnly for multipart/form-data.protected HttpSessionHTTP session for nonce validation.protected MapNot for multipart/form-data, will be null.Constructor Summary
ConstructorsConstructorDescriptionLeaves the form state unset;setContextId(String)supplies the context and preferences.Method Summary
Modifier and TypeMethodDescriptionintHow many graphs the configured listeners will draw.(package private) static inteffectiveRefresh(int saved, boolean graphingDisabled) The auto-refresh delay a page render should actually use.The stat names the user has switched on for graphing.We have to do this here becauseprocessForm()isn't called unless the nonces are good.getForm()The graph display configuration form posted to /graphs.The thumbnail list for the graphs page, one anchor-wrapped image per enabled stat plus a tile per active group.This must be output in the jsp since <meta> must be in the <head>.intThe refresh delay the current render should actually use, in seconds.For single stat page; stat = "bw.combined" treated specially.private static Stringlink(String stat, boolean showEvents, int periodCount, int end, int width, int height, boolean hideLegend, boolean hideRestarts) Link to the graph page for a stat.protected voidThis was a HelperBase but now it's a FormHandler.private StringrenderGroupTiles(Set<String> enabledStats, boolean hideLegend, boolean hideRestarts, long now) Emit one tile per active group, each plotting its members as overlaid lines.(package private) static booleanresolveShowEvents(String param, boolean current) Resolves the requested events mode against the mode in force.private voidSilently save settings if changed, no indication of success or failure.voidShorter form ofsetPeriodCount(String)bound to the c= URL parameter.voidsetContextId(String contextId) Set the defaults after we have a context.voidEnds the view window that many periods before the most recent one.voidsetGraphCombine(String foo) Sets whether related stats are merged into one overlaid plot.voidsetGraphFill(String foo) Sets whether graphs are drawn with filled areas.voidsetGraphGlow(String foo) Sets the glow effect drawn around graph lines.voidsetGraphSmooth(String foo) Sets bezier curves in place of a staircase plot.voidShorter form ofsetHeight(String)bound to the h= URL parameter.voidSets the image height in pixels.voidsetHideLegend(String foo) Sets whether the legend is suppressed on graphs.voidsetHideRestarts(String foo) Sets whether restart markers are suppressed on graphs.voidsetPeriodCount(String str) Sets how many periods the graph spans.voidsetPersistent(String foo) Enables storing graph data on disk; the submitted value is not examined.voidsetRefreshDelay(String str) Sets how often the graph refreshes, in seconds.voidChooses between plotting individual events and plotting averages.voidFor single stat page.voidSets whether graph axes are labelled in UTC instead of local time.voidShorter form ofsetWidth(String)bound to the w= URL parameter.voidSets the image width in pixels.(package private) static StringurlStatName(String name) Percent-encode a stat or group name for use as a URL query value.Methods inherited from class FormHandler
_t, _t, _t, _x, addFormError, addFormError, addFormErrorNoEscape, addFormErrorNoEscape, addFormNotice, addFormNotice, addFormNoticeNoEscape, addFormNoticeNoEscape, getErrors, getJettyString, getNotices, isAdvanced, resolveEffectiveAction, setAction, setNonce, setRequestWrapper, setSettings, storeMethod, storeSession, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected voidaddFormError(String errorMsg) Add an error message to display Use if it does not include a link.protected voidaddFormError(String errorMsg, boolean canClose) Add an error message to display Use if it does not include a link.protected voidAdd an error message to display Use if it includes a link or other formatting.protected voidaddFormErrorNoEscape(String msg, boolean canClose) Add an error message to display Use if it includes a link or other formatting.protected voidaddFormNotice(String msg) Add a non-error message to display Use if it does not include a link.protected voidaddFormNotice(String msg, boolean canClose) Add a non-error message to display Use if it does not include a link.protected voidAdd a non-error message to display Use if it includes a link or other formatting.protected voidaddFormNoticeNoEscape(String msg, boolean canClose) Add a non-error message to display Use if it includes a link or other formatting.Display any error messages (processing the form if it hasn't been yet).protected StringgetJettyString(String key) FormHandler.setSettings(Map)must have been called previously Curses Jetty for returning arrays.Display any non-error messages (processing the form if it hasn't been yet).booleanSame as HelperBase.static StringresolveEffectiveAction(String action, Map<?, ?> settings) Resolve which operation the user actually requested.voidAction value.voidNonce value.voidOnly set by formhandler.jsi for multipart/form-data.voidsetSettings(Map settings) For many forms, it's easiest just to put all the parameters here.voidstoreMethod(String val) Call this to prevent changes using GET.voidstoreSession(HttpSession session) For nonce validation.voidstoreWriter(Writer out) Store the output writer for inline form processing.
Field Details
_periodCount
private int _periodCountNumber of stat periods shown on the graph._showEvents
private boolean _showEventsWhether event markers are drawn._width
private int _widthGraph width in pixels._height
private int _heightGraph height in pixels._refreshDelaySeconds
private int _refreshDelaySecondsSeconds between graph refreshes._persistent
private boolean _persistentWhether the settings are saved to the config._graphHideLegend
private boolean _graphHideLegendWhether the legend is hidden._graphHideRestarts
private boolean _graphHideRestartsWhether restart markers are hidden._graphGlow
private boolean _graphGlowWhether the graph line glows._graphSmooth
private boolean _graphSmoothWhether the graph line is smoothed._graphFill
private boolean _graphFillWhether the area under the line is filled._graphCombine
private boolean _graphCombineWhether in and out rates share one line._useUtc
private boolean _useUtcWhether graph times are shown in UTC._stat
The stat name being graphed._end
private int _endWhich of the two stat values to graph, -1 for both.PROP_X
PROP_Y
PROP_REFRESH
Config key for the refresh delay.- See Also:
PROP_PERIODS
Config key for the period count.- See Also:
PROP_EVENTS
Config key for showing event markers.- See Also:
PROP_HIDE_LEGEND
Config key for hiding the legend.- See Also:
PROP_HIDE_RESTARTS
Config key for hiding restart markers.- See Also:
PROP_GLOW
PROP_SMOOTH
PROP_FILL
PROP_COMBINE
Config key for combining the rates.- See Also:
PROP_UTC
DEFAULT_REFRESH
private static final int DEFAULT_REFRESHDefault refresh delay, in seconds.- See Also:
DEFAULT_PERIODS
private static final int DEFAULT_PERIODSDefault number of stat periods shown.- See Also:
DEFAULT_HIDE_LEGEND
private static final boolean DEFAULT_HIDE_LEGENDThe legend is shown by default.- See Also:
DEFAULT_HIDE_RESTARTS
private static final boolean DEFAULT_HIDE_RESTARTSRestart markers are shown by default.- See Also:
MIN_X
MIN_Y
MIN_C
MAX_C
MIN_REFRESH
private static final int MIN_REFRESHSmallest refresh delay accepted, in seconds.- See Also:
AMP
Escaped ampersand reused in the graph links.- See Also:
SHOW_EVENTS_PARAM
Query parameter for the event markers.- See Also:
HIDE_LEGEND_PARAM
Query parameter for the legend.- See Also:
HIDE_RESTARTS_PARAM
Query parameter for the restart markers.- See Also:
PERIOD_COUNT_PARAM
Query parameter for the period count.- See Also:
WIDTH_PARAM
Query parameter for the graph width.- See Also:
HEIGHT_PARAM
Query parameter for the graph height.- See Also:
TIME_PARAM
Query parameter for the graph end time.- See Also:
STAT_PARAM
Link prefix to the stat detail page.- See Also:
GRAPH_HREF
HEX
private static final char[] HEXHex digits for the percent-escapes urlStatName() emits._hideLegend
private boolean _hideLegendWhether this graph hides its legend.times
private static final int[] timesPeriod lengths offered on the graph page.
Constructor Details
GraphHelper
public GraphHelper()Leaves the form state unset;setContextId(String)supplies the context and preferences.
Method Details
setContextId
Set the defaults after we have a context.- Overrides:
setContextIdin classFormHandler- Parameters:
contextId- beginning few characters of the routerHash, or null to pick the first one we come across.
getRefreshMeta
This must be output in the jsp since <meta> must be in the <head>.- Returns:
- the refresh meta
getRefreshValue
public int getRefreshValue()The refresh delay the current render should actually use, in seconds.- Returns:
- the delay in seconds, or -1 when graph generation is unavailable
effectiveRefresh
static int effectiveRefresh(int saved, boolean graphingDisabled) The auto-refresh delay a page render should actually use.Refreshing is pointless while graph generation is unavailable, and hammering a console that cannot render is worse than showing nothing, so the delay is suppressed for that one render. It is deliberately not persisted: graph generation can come back, and writing the suppression into the config made it permanent, so once graphing had been unavailable for any reason the graphs page would freeze on its first paint and never refresh again, even after the router had recovered.
- Parameters:
saved- the configured delay in secondsgraphingDisabled- whether graph generation is currently unavailable- Returns:
- the delay to use for this render, or -1 to suppress refreshing
setPeriodCount
Sets how many periods the graph spans.- Parameters:
str- period count in minutes; non-numeric text is ignored and numbers are clamped to MIN_C..MAX_C
setE
Ends the view window that many periods before the most recent one.- Parameters:
str- how many periods back to end, so 0 ends at the latest period; non-numeric text is ignored
setC
Shorter form ofsetPeriodCount(String)bound to the c= URL parameter.- Parameters:
str- period count in minutes; non-numeric text is ignored and numbers are clamped to MIN_C..MAX_C
setShowEvents
Chooses between plotting individual events and plotting averages.- Parameters:
b- true to plot individual events, false to plot averages; an absent, empty or unrecognised value leaves the current mode in force
resolveShowEvents
Resolves the requested events mode against the mode in force.An absent or empty parameter means "not specified", and the mode already in force - which came from
routerconsole.graphEvents- stands. It must not be read as a request for events: the enlarged-graph link only emitsshowEventswhen events are on, so a time-mode link omits it, and the old!"false".equals(b)turned that omission intotrue. Opening the larger view of a time graph silently switched it to events and contradicted the configured default. The two URL-building sites disagreed about whether the parameter is always present; this makes the reader tolerant of its absence instead.The value is also parsed symmetrically with the way it is written. One link emits
showEvents=1and the image sources emitshowEvents=true|false, but the reader recognised only the literal string"false"- soshowEvents=0, a perfectly ordinary way to spell it, was read as a request for events.- Parameters:
param- the request parameter, may be null or emptycurrent- the mode currently in force- Returns:
- the mode to use
setHeight
Sets the image height in pixels.- Parameters:
str- image height in pixels; non-numeric text is ignored and numbers are clamped to MIN_Y..MAX_Y
setH
Shorter form ofsetHeight(String)bound to the h= URL parameter.- Parameters:
str- image height in pixels; non-numeric text is ignored and numbers are clamped to MIN_Y..MAX_Y
setWidth
Sets the image width in pixels.- Parameters:
str- image width in pixels; non-numeric text is ignored and numbers are clamped to MIN_X..MAX_X
setW
Shorter form ofsetWidth(String)bound to the w= URL parameter.- Parameters:
str- image width in pixels; non-numeric text is ignored and numbers are clamped to MIN_X..MAX_X
setRefreshDelay
Sets how often the graph refreshes, in seconds.- Parameters:
str- refresh delay in seconds; a positive value is raised to MIN_REFRESH, zero or negative selects never refresh, and non-numeric text is ignored
setPersistent
Enables storing graph data on disk; the submitted value is not examined.- Parameters:
foo- the persistent checkbox value, ignored
setGraphGlow
Sets the glow effect drawn around graph lines.- Parameters:
foo- only the exact textfalseturns the glow off; any other value enables it
setGraphSmooth
Sets bezier curves in place of a staircase plot.- Parameters:
foo- only the exact textfalseturns smoothing off; any other value enables it
setGraphFill
Sets whether graphs are drawn with filled areas.- Parameters:
foo- only the exact textfalseturns filling off; any other value enables it
setGraphCombine
Sets whether related stats are merged into one overlaid plot.- Parameters:
foo- only the exact textfalseturns combining off; any other value enables it
setUseUtc
Sets whether graph axes are labelled in UTC instead of local time.- Parameters:
foo- only the exact textfalseturns UTC off; any other value enables it
setHideLegend
Sets whether the legend is suppressed on graphs.- Parameters:
foo-truehides the legend andfalseshows it; any other value leaves the current setting alone
setHideRestarts
Sets whether restart markers are suppressed on graphs.- Parameters:
foo-truesuppresses them andfalserestores them; any other value leaves the current setting alone
setStat
For single stat page.- Parameters:
stat- the rate name to plot, or a group id when combining is on
getImages
The thumbnail list for the graphs page, one anchor-wrapped image per enabled stat plus a tile per active group.- Returns:
- the markup for the thumbnails, or the empty string when graphs are not available
renderGroupTiles
private String renderGroupTiles(Set<String> enabledStats, boolean hideLegend, boolean hideRestarts, long now) Emit one tile per active group, each plotting its members as overlaid lines.A group appears only when at least two members are enabled and carry data, so enabling a single stat is never silently turned into a combined plot.
- Parameters:
enabledStats- the enabled stats, from which group members are pickedhideLegend- true to hide the legend, shrinking the tile height to matchhideRestarts- true to hide restart markers on the tile's graphsnow- the graph end time in ms since epoch- Returns:
- markup for every qualifying group, empty when none qualify
enabledStatNames
The stat names the user has switched on for graphing.- Parameters:
ss- the graph generator- Returns:
- enabled stat names, without period suffixes
countGraphs
public int countGraphs()How many graphs the configured listeners will draw.- Returns:
- the number of configured graph listeners, or 0 if graphs are disabled
getSingleStat
For single stat page; stat = "bw.combined" treated specially.- Returns:
- the single stat
urlStatName
Percent-encode a stat or group name for use as a URL query value.Only the space was escaped before, so a tunnel nickname carrying &, +, = or % silently split or corrupted the graph link, since per-tunnel stats are named
[nickname] InBpsand the nickname is user input. Everything outside the unreserved set of RFC 3986 is escaped, UTF-8, uppercase hex. The name itself is never rewritten: the space thatGraphGroupspairs In/Out rates on stays intact in the model and only becomes%20on the wire, and a plain name such asbw.sendRatecomes back byte-identical.URLEncoder is deliberately not used: it turns the space into
+and rewrites characters that are already safe, which would change URLs that work today.- Parameters:
name- the stat or group name as registered- Returns:
- the name safe to append to a query value
link
private static String link(String stat, boolean showEvents, int periodCount, int end, int width, int height, boolean hideLegend, boolean hideRestarts) Link to the graph page for a stat.- Parameters:
stat- the stat name to link toshowEvents- true to ask the graph page for event markersperiodCount- the number of periods to plot, sent as the c parameterend- the end-time offset, left out of the URL when 0 or lesswidth- the graph width in pixelsheight- the graph height in pixelshideLegend- this page's legend setting, written inverted into the URLhideRestarts- this page's restart-marker setting, passed through- Returns:
- the opening anchor tag for the graph page with these parameters
getForm
The graph display configuration form posted to /graphs.- Returns:
- the form markup, or the empty string when graphs are not available
getAllMessages
We have to do this here becauseprocessForm()isn't called unless the nonces are good.- Overrides:
getAllMessagesin classFormHandler- Returns:
- the all messages
processForm
protected void processForm()This was a HelperBase but now it's a FormHandler.- Specified by:
processFormin classFormHandler
saveSettings
private void saveSettings()Silently save settings if changed, no indication of success or failure.