monoblok docs
Docs menu · LVC, stats and snapshots

Server

LVC, stats and snapshots

The last-value cache supplies recent values to new subscribers, live counters report rule activity, and snapshots preserve cached values and patchbay state across restarts.

$LVC.*: last-value-cache stream#

Top-level (lvc ...) forms opt subjects into the last-value cache. Subscribing to $LVC.foo.bar joins a live stream of foo.bar: current cached value first (if any), then every subsequent opted-in publish. Wildcards work. PUB $LVC.* is rejected.

EDN
(lvc ["sensors.>" "alerts.>"])
text
PUB foo.bar 11      ; cache = 11
PUB foo.bar 12      ; cache = 12
SUB $LVC.foo.bar    ; -> immediately receives 12
PUB foo.bar 13      ; -> subscriber receives 13

Absent (lvc ...), LVC is off and the publish path does no cache work. --no-lvc disables configured LVC filters.

$STATS.* can be cached too, but only with an explicit stats filter such as (lvc ["$STATS.>"]). A broad (lvc [">"]) keeps stats out of the LVC unless you opt in.

Why it matters#

Subscribe to $LVC.car.*.*.stable to receive the last cached value for each matching subject, followed by live updates. This lets a dashboard display recent readings even when no new messages are arriving.

shell
# Publish a value before subscribing.
nats pub sensors.temp 23.5

# Later, subscribe.
nats sub '$LVC.sensors.temp'
# -> prints "23.5" immediately

Single-quote any subject starting with $ so your shell does not try to expand it.

Rule output is cached when its subject matches an LVC filter. A subscriber to $LVC.sensors.temp.stable therefore receives the latest processed value on connection.

Reading the cache from a rule#

Rules can read the cache with (last SUBJECT), which is how one subject's rule sees another subject's value, and answer NATS requests from it with reply!. The HTTP adapter exposes the same cache at GET /latest/<subject>.

EDN
(lvc ["temp.>"])

(on "ask.outside"
  (reply! (last "temp.outside")))

$STATS.*: live counters#

The server publishes cumulative decimal counters on $STATS.* every 60 seconds by default. Use --stats-tick-ms MS to change the cadence.

subjectmeaning
$STATS.global.pubsaccepted inbound client PUBs since start
$STATS.rules.<i>.emittedsuccessful publish!-style emits by rule, 0-based
$STATS.rules.<i>.suppressedgate/window suppressions by rule, 0-based
$STATS.bridge.publishedpublishes forwarded to the remote NATS cluster
$STATS.bridge.droppedbridge publishes that failed or were dropped
$STATS.import.receivedremote NATS messages accepted by import
$STATS.import.processedimported messages evaluated by patchbay
$STATS.import.droppedimported messages dropped before evaluation
$STATS.import.failedimported messages whose patchbay evaluation failed

Client publishes to $STATS.* are rejected. Subscribe to $STATS.> for the live stream, or add (lvc ["$STATS.>"]) if late joiners should receive the most recent tick immediately.

The per-rule counters are the quickest way to confirm a gate is doing what you expect: emitted climbing while suppressed stays at zero means the gate never closes.

Snapshots#

Warm-start from disk so restarts don't lose the cache or the state inside gates and windows.

text
monoblok --snapshot /var/lib/monoblok/state.mblk --snapshot-every 10

--snapshot PATH loads on startup if it exists (missing is fine). --snapshot-every SECONDS runs a periodic dump using atomic temp-file + rename. If the patchbay file changes between runs, LVC entries still load; rule state for any rule whose filter no longer matches at its recorded position is skipped with a warning.

Snapshot files are format version 5. A snapshot in format 3 or 4 still loads its LVC entries, but its rule state is skipped with one warning (anything older is ignored entirely), so the first restart after upgrading loses window and gate state.

Patchbay state is per call site and subject (two uses of the same stateful form in one rule keep separate state). Avoid unbounded subject tokens such as timestamps, user IDs, or raw device-generated strings unless you intend to create state for each one.

What a snapshot holds#

  • Every last-value cache entry.
  • Patchbay state: the last value inside each squelch and deadband, window rings, edge and transition state, counters, and in-progress bars.

Rule state is identified by the rule's position and filter plus the call site and subject of each slot. Time-window slots are re-armed on load; a slot whose deadline passed while the server was down fires immediately on startup. every timers are not stored; they are recreated when the patchbay loads.

The systemd unit writes a snapshot every 10 seconds and on stop, so a crash or reboot loses at most one snapshot interval of conditioning state.

MIT licensed · © 2026 Alex Reid
Lexvica offers solutions built with monoblok.