Class WebEngineHistory
- All Implemented Interfaces:
AutoCloseable
The daily totals. WebEngineStats counts every connect for its day in UTC; this class takes those day counts (WebEngineStats.drainDays()) into IZS.WEB_ENGINE_DAYS, one row per day and group row (application, platform, product, OS major, engine major, status), every FLUSH_INTERVAL on one virtual thread, at the server's stop (stop()), and before a reset. The totals of a period (period(int)) and the trend per day (trend(int)) are read from the table with what is counted and not yet written added, so a page never lags. Days older than the retention setting are deleted when a day ends (the first flush of a new UTC day).
The warning (section (b) of the order): an application whose assessed sessions over the period - ended, behind and patched; a session that is not assessed says nothing about patching - are unpatched (ended or behind) in a share of at least its threshold, in percent, is a WebEngineHistory.Warning: the Dashboard shows it, and when the server setting says so, the administrators are mailed, at most once per application per day (IZS.WEB_ENGINE_MAIL). The threshold is the server's (WebEngineHistory.Settings.unpatchedThreshold()) unless the application's definition sets its own (WebEngineHistory.Settings.applicationThreshold(String)); 0 turns the warning off. Fewer than MIN_ASSESSED assessed sessions are too few to call a share: no warning.
Reset and undo. reset(String) clears the since-start counters of the live counts and every stored daily total, after writing a copy of exactly what it clears to IZS.WEB_ENGINE_RESET and IZS.WEB_ENGINE_RESET_ROWS, with the administrator's name and the time until which undo(String) may restore it (the undo setting, default 7 days). The undo puts the daily totals back and ADDS the saved since-start connects to what was counted since the reset, so nothing counted in between is lost; only the last reset can be undone, and once. The backup is deleted by the undo, by the next reset, or when its time is up. "Active now" is live and never reset. Both ask the administrator first in ServerAdmin, and each is logged with one INFO line naming the administrator.
The tables are created here when they are absent, as DeviceTokenStore creates its own: the base script runs on an empty database only. The SQL is SQL-92 and runs unchanged on Derby, PostgreSQL and MySQL. A table that cannot be created makes the history unavailable: the live counts of WebEngineStats go on, the pages show no stored totals, one SEVERE line says so at most once a minute, and nothing here ever disturbs a client session.
Thread safe: every method takes the one monitor of the instance. The clock is injected (setClock(Clock)), so that the tests and the rigs drive time.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe connects of one day per status.static interfaceSends a warning mail to the administrators.static final recordThe connects of a period, from its first day to its last, both in UTC.static final recordThe last reset, as long as it can be undone.static interfaceThe settings the history reads, asked at every use so that a saved change applies at once; in the server theServerSettingsand the application definitions.static enumWhat an undo did.static final recordThe answer ofundo(String).static final recordAn application over the threshold.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe delay of the first write after the server's start.static final DurationHow often the day counts are written to the database: every 15 minutes, so that a server that is killed loses at most that much; the day's end and the server's stop write as well.static final intThe fewest assessed sessions of an application over the period for which a share is called: one unpatched session of one is no share worth a warning.Constructor Summary
ConstructorsConstructorDescriptionWebEngineHistory(ConnectionSource connections, WebEngineStats stats, Clock clock, WebEngineHistory.Settings settings, WebEngineHistory.Mailer mailer) Constructs the history.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Same asstop().intCreates the tables that are absent.getClock()Gets the clock.Gets the settings.getStats()Gets the live counts this history stores.booleanTells whetherstop()was called.Gets the last reset while its backup exists, expired or not.period(int days) Gets the connects of the last days, today included: the stored daily totals plus what is counted and not yet written.Resets the counts: writes the day counts, copies every stored daily total and every since-start counter into the backup of this reset (replacing the backup of the last one), deletes the stored daily totals and resets the since-start counters of the live counts.voidSets the clock of "now" and "today": for the tests and the rigs, which move time; a server never calls it.start()Starts the writer: the tables are made sure of, and the day counts are written everyFLUSH_INTERVALfromFIRST_DELAYon.voidstop()Stops the writer and writes the day counts a last time: called when the server stops, while its database is still up.voidtick()Does the work of one tick, now: writes the day counts, does the work of a day's end when the UTC day changed since the last tick (the retention, the expired backup), and checks the threshold of every application, mailing where the settings say so.toString()The schema, the tables and the settings, for the log.trend(int days) Gets the connects per day of the last days, today included and newest first, with what is counted and not yet written added: the trend per verdict of ServerAdmin's Web engines page.Undoes the last reset: the stored daily totals it cleared come back (added to whatever was stored for the same day and group since), the since-start counters get the saved values added to what was counted since the reset, counting starts again where it did before the reset, and the backup is deleted.warnings(WebEngineHistory.Period period) Finds the applications over their threshold in a period: the share of their assessed sessions that were unpatched reaches the threshold that applies to them, and at leastMIN_ASSESSEDsessions were assessed.
Field Details
FLUSH_INTERVAL
How often the day counts are written to the database: every 15 minutes, so that a server that is killed loses at most that much; the day's end and the server's stop write as well.FIRST_DELAY
The delay of the first write after the server's start.MIN_ASSESSED
public static final int MIN_ASSESSEDThe fewest assessed sessions of an application over the period for which a share is called: one unpatched session of one is no share worth a warning.- See Also:
Constructor Details
WebEngineHistory
public WebEngineHistory(ConnectionSource connections, WebEngineStats stats, Clock clock, WebEngineHistory.Settings settings, WebEngineHistory.Mailer mailer) Constructs the history. Nothing runs untilstart().- Parameters:
connections- The connection source; in the serverDBUtilities::getPooledConnection.stats- The live counts of the server.clock- The clock of "now" and "today".settings- The settings.mailer- The mail, null when the server cannot mail.
Method Details
setClock
Sets the clock of "now" and "today": for the tests and the rigs, which move time; a server never calls it.- Parameters:
clock- The clock.
getClock
getStats
getSettings
start
Starts the writer: the tables are made sure of, and the day counts are written everyFLUSH_INTERVALfromFIRST_DELAYon. Never throws: a database that refuses the tables is logged, and the writer tries again at every tick.- Returns:
- This history.
stop
public void stop()Stops the writer and writes the day counts a last time: called when the server stops, while its database is still up. Idempotent; never throws.close
isStopped
tick
public void tick()Does the work of one tick, now: writes the day counts, does the work of a day's end when the UTC day changed since the last tick (the retention, the expired backup), and checks the threshold of every application, mailing where the settings say so. The rigs and the tests call it to stand for the passing of time. Never throws for a database failure: it is logged, and the counts stay in memory for the next tick.period
Gets the connects of the last days, today included: the stored daily totals plus what is counted and not yet written.- Parameters:
days- The days, at least 1.- Returns:
- The period, never null: all zero when the history is unavailable (logged).
trend
Gets the connects per day of the last days, today included and newest first, with what is counted and not yet written added: the trend per verdict of ServerAdmin's Web engines page. A day without a connect has a row of zeros.- Parameters:
days- The days, at least 1.- Returns:
- The days, newest first; all zero when the history is unavailable (logged).
warnings
Finds the applications over their threshold in a period: the share of their assessed sessions that were unpatched reaches the threshold that applies to them, and at leastMIN_ASSESSEDsessions were assessed. The overflow rows belong to no application and are not judged.- Parameters:
period- The period.- Returns:
- The warnings, by application ID; empty for none.
reset
Resets the counts: writes the day counts, copies every stored daily total and every since-start counter into the backup of this reset (replacing the backup of the last one), deletes the stored daily totals and resets the since-start counters of the live counts. "Active now" is not touched. Logged with one INFO line naming the administrator.- Parameters:
admin- The administrator's user name, for the backup and the log.- Returns:
- The reset, whose
undoUntilsays until when it can be undone (equal to its time when the undo setting is 0: no undo). - Throws:
SQLException- If the database refuses: nothing is cleared.
undo
Undoes the last reset: the stored daily totals it cleared come back (added to whatever was stored for the same day and group since), the since-start counters get the saved values added to what was counted since the reset, counting starts again where it did before the reset, and the backup is deleted. Refused, with the backup deleted, when the time to undo has passed; a second undo finds no backup. Logged with one INFO line naming the administrator.- Parameters:
admin- The administrator's user name, for the log.- Returns:
- What was done.
- Throws:
SQLException- If the database refuses: nothing is changed.
lastReset
Gets the last reset while its backup exists, expired or not.- Returns:
- The reset, or null when there is none to undo; null too when the history is unavailable (logged).
ensureSchema
Creates the tables that are absent. Another server on the same database may do so at the same moment: a table it created first is used as found.- Returns:
- The tables created here, 0 to 4.
- Throws:
SQLException- For SQL errors: a table is absent and cannot be created.
toString