Skip to content

Live Monitoring ​

The case foresight was built for: a job runs for hours, appends its residuals and forces to text files, and you want to watch them — in a browser on your workstation, or in a terminal over ssh.

The job side ​

Nothing to link: write the monitored quantities as columns, one line per step, and flush.

fortran
write(log_unit, '(I0,2(1X,ES14.6E3))') it, res_rho, res_mom
flush(log_unit)

See Data Files for the format and for what happens when a line is read half-written.

In a browser ​

bash
foresight --watch residuals.gp

The script is run once, then the script and its data files are polled every second; on any change the script runs again and rewrites residuals.html. The page reloads itself every period (rounded to whole seconds, at least 1; a script's own set terminal html refresh S wins) and keeps your zoom, because the view is stored in its URL as data values, not as screen positions. Rewrites are atomic (a temporary file renamed over the page), so a reload never catches half a page.

a watched run (an animation)
a watched run (an animation)open SVG ↗

The page above is a run as --watch shows it: the residuals growing as the solver writes them, the seven-segment readouts on the last values, the time axis of the wall clock advancing (each frame is the page foresight writes after one more block of iterations).

A longer period for slow jobs: foresight --watch 10 residuals.gp.

To watch the latest iterations only, zoom to a window of the width you want and press f: at each reload the window slides to the end of the data and the y range fits what it shows (Following a live run). A click on a key entry hides a series that crowds the others; both settings survive the reloads, in the page URL.

Over ssh ​

bash
foresight --watch -e "set terminal dumb" residuals.gp
foresight --watch -e "set terminal block braille ansi" residuals.gp

The plot is drawn in text on the standard output; each re-render clears the screen and redraws in place. No browser, no X forwarding, no port to open.

the terminal redrawn in place (an animation)
the terminal redrawn in place (an animation)open SVG ↗

block braille draws with Braille dots, 2 x 4 per character, and ansi colors the series (Output Formats): the curves of a terminal plot then read almost as a picture.

A cockpit for a run ​

with readout shows the newest value of a column in seven-segment digits, as a 1980s car dashboard: the iteration, the residual, a coefficient, beside or over the curves. A readout follows its file at every cycle, like any plot item.

gnuplot
set readout horizontal
plot 'run.dat' u 1 w readout format '%6.0f' t 'ITER', '' u 2 w readout format '%9.2e' t 'RESIDUAL'

The glass is fixed by the format, so the digits never jump between two reloads; a log not written yet shows dashes. In the terminal the digits are drawn with characters, so the cockpit works over ssh too. See Readouts and the cookbook.

A loop in the script ​

A gnuplot 6.0 script can follow a run by itself, without --watch: a loop that plots and pauses.

gnuplot
set terminal html refresh 5; set output 'run.html'
while (1) {
  plot 'run.dat' u 1:2 w l t 'residual'
  pause 5
}

Each plot rewrites the page whole (written to a temporary file, then renamed), the browser reloads it every 5 seconds. Stop the loop with Ctrl-C. reread, the older idiom, is an error: gnuplot 6.0 rejects it as deprecated. --watch does more for the same job: it re-runs the script only when a data file or the script changes, survives a failing cycle, and needs no loop in the script. See Shell commands, reset and pause and the cookbook.

Robustness ​

  • An error in one cycle — a data file briefly missing, a script saved with a typo — is reported and watching goes on.
  • Change detection compares each file's size and a hash of its content — all of it up to 1 MiB, the first and last 64 KiB beyond. Appends, a restarted job rewriting its log, an edit of the script that keeps its length (lw 2 → lw 3) are all caught; only a same-size change in the middle of a file larger than 1 MiB is missed, which an append-only log never does. File modification times are not used: standard Fortran cannot read them, and their resolution is seconds on some filesystems (network shares, WSL).
  • --max-cycles N stops after N polls, for scripted use.

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.