|hadron|: QQT-008 the stats line and the Prometheus body are two renderings of one Snap, never two sources of numbers — Metrics::snapshot reads the live state once and both formatters consume it, so the endpoint and the log line can never disagree about what the tunnel is doing. A second calculation anywhere on that path breaks the contract silently: the two surfaces would drift apart with no test to catch it.
--stats answers one question without any infrastructure: what is this tunnel doing right now, on this box, seen from a terminal? It is a second rendering of the numbers the Prometheus endpoint already serves — never a second source of numbers.
The sink: this process’s own stderr
The line goes where every other line this tool writes goes. That is the whole argument, and it is what makes the feature work with zero infrastructure:
- A terminal shows it because the process was started there.
- journald shows it because the unit’s
StandardOutput/StandardErrordefault tojournal, sojournalctl -u <unit> -fis the live view with no flag, no socket, no config. journald’s own rate limit (journald.conf(5):RateLimitBurstdefaults to 10000 messages perRateLimitIntervalSecof 30 s, per service) sits three orders of magnitude above a 10 s cadence, so a stats line is never the traffic that gets dropped. - A redirected file shows it because
> server.log 2>&1captures stderr like any other line — the shape the rental box’s start line already uses.
What it deliberately is not:
- Not stdout. stdout is the tool’s product channel —
-hand-V, the only things a caller pipes. The whole operational lane (up’s plan included) already writes throughlog_*to stderr, soqqt up --dry-runprints nothing on stdout. A stats line there would be the first uncontracted byte on that channel, interleaving with-h | lessand-Vcapture. Diagnostics belong on stderr; that split is the reason the Unix convention exists. - Not a status file. A file needs a path, a permission story, and rotation, and it goes stale in a way a log never does — a reader cannot tell a live number from the number left by a process that died an hour ago. The process’s own stream ends when the process does.
- Not a Unix socket. A socket puts a second listener and a second protocol on the box to answer a question a
tailalready answers. It earns its keep when a scraper needs a pull interface — which is exactly what--enable-metricsalready is. - Not a signal-triggered dump. The
SIGUSR1-dumps-stats convention (sendmail, tor, restic) is right when a process otherwise has no log channel, or when the dump is rare and expensive to produce. Here the numbers are a sub-millisecond local read of quinn’s per-connection stats, so a cadence is cheaper for the operator than remembering a signal name.
The format: one logfmt line
Fields are key=value pairs on one line, units carried in the value:
role=server remote=0.0.0.0:46100 version=0.8.0 cc=bbr up=40s connected=1
rtt=1.4ms rtt_min=205us jitter=407us cwnd=763.8KiB mtu=1389 bw_tx=0B
bw_rx=0B tx=797.4KiB rx=792.3KiB tx_pkts=662 rx_pkts=639 sent=663 lost=0
loss=0.00% cong=0 blackholes=0 streams_active=0 streams_total=12 conns=1
handshakes=1
(shown wrapped; the wire form is a single line)
logfmt is the format that reads acceptably to a human and parses mechanically at the same time — Heroku’s router established it, Splunk recommends it, and the trade it makes is explicit: not optimal for either reader, good for both. The alternatives lose on one side. JSON lines parse perfectly and read poorly at a terminal, and they cost brackets and quotes on every field for a line an operator mostly eyeballs. A fixed column table reads well by eye and breaks the moment a field’s width changes.
Two properties carry the greppability:
One record per line. Nothing in the line may contain a newline; a value that would break that (
remote, if it ever carried whitespace) is quoted, and the escapes are applied rather than trusted away — a quote, a backslash, and a newline each become\",\\, and\n, so a-rnaming a host with a newline in it still emits one record. The endpoint’s own label escape is the same set, which is what lets the two renderings carry one observation.Every pair a whitespace-delimited
key=value.awk,cut, and aforloop over$@all work with no parser:journalctl -u qqt-client -f | awk '{for(i=1;i<=NF;i++) if($i ~ /^loss=/) print $i}'
Units in the value (rtt=1.4ms, tx=797.4KiB) follow the same choice the Heroku router makes (connect=4ms, bytes=1653): an operator reading a terminal needs the magnitude, and a script splitting on = gets a number and a unit it can compare or strip. Counters that are naturally unitless (packet counts, streams, handshakes) carry none.
One data source, two renderings
Metrics::snapshot reads the live state once and returns a Snap; the Prometheus body and the stats line both format a Snap. Neither renderer holds numbers of its own, so the two can never disagree about what the tunnel is doing — the endpoint and the log line are the same observation in two shapes. Every measured key on the line names the /metrics series it carries, with two exceptions that are line-only: loss is the percentage the Prometheus body leaves to the scraper to divide from qqt_sent_packets_total and qqt_lost_packets_total, and final is a marker, not a measurement — it says the run ended cleanly rather than carrying a number.
The converse does not hold, and the difference matters: a series need not appear on the line, because the line is a human-scale view and the endpoint is the full set. qqt_lost_bytes_total is the standing example. So the invariant is one Snap, not one key set — a labelled family (a per-forward breakdown, say) belongs on the endpoint alone rather than being flattened into a key=value pair that loses the label it was named for.
Conformance and compression
The body declares a # TYPE for every family and is served as text/plain; version=0.0.4, which is what a scraper’s own parser is keyed on. A # TYPE is emitted by the same call that emits its sample, so a family cannot gain a value without its declaration — and a test walks the body asserting every declared class against one table, so a wrong or missing type fails rather than ships.
gzip is negotiated, never assumed: a request naming gzip gets the compressed body, any weight spelling that means zero (gzip;q=0, q=0.0, q=0.000) gets plain text, and a compression failure falls back to identity rather than losing the scrape. A request that names no coding at all gets plain text, because that is what keeps a bare curl /metrics readable. Prometheus asks for gzip on every scrape by default, so a target that cannot answer costs the wire a body it never had to send.
Failures, and the denominator they need
qqt_streams_total only moves once a stream is established, so on its own it is a success count: zero means either “nothing arrived” or “everything was rejected”, which are opposite problems with opposite fixes. qqt_stream_attempts_total counts the try, at the one place every forward passes through, so the two together answer the question a scraper actually has.
The failures carry a bounded reason label, and each reason names the operator’s next move rather than the code site that noticed it:
| family | reasons | the question it answers |
|---|---|---|
qqt_ingress_rejected_total |
frame, control, unregistered |
is the peer compatible, or hostile? |
qqt_target_dial_failures_total |
resolve, connect |
can this side reach the target? |
qqt_stream_open_failures_total |
open_bi, header_write |
is the link dying under the forwards? |
qqt_reverse_register_failures_total |
reply, refused |
is a published -R port dead? |
qqt_listener_accept_errors_total |
fd, other |
raise LimitNOFILE? |
fd is singled out because it is the one accept failure an operator acts on, and the log already names it (fd_exhausted). Every reason slot is emitted even at zero, so an alert reads a real zero instead of “no data” — a family that appeared only after its first failure would make a healthy tunnel look absent.
A refused -R deserves its own family rather than a line among the others: it is the one failure where the tunnel is up and a port an operator published is dead, and no other counter can show it.
Per-forward attribution, keyed on the bind
qqt_forward_{tx,rx}_bytes_total and qqt_forward_errors_total carry a forward label naming the bind the listener took — the address an operator typed, and the one identity that distinguishes two specs pointing at one target. A port-0 spec names the port the OS chose, because the slot is created when the listener binds rather than when the spec is parsed.
The label is bounded by the operator’s own spec count and never comes from the peer. That is the whole reason it is the bind and not the remote address: a server’s client population churns, so peer-keyed labels are unbounded, and the -l target would collide two specs that share one.
Bytes flush once when the stream ends, from the counts copy_bidirectional returns. A per-chunk counter costs roughly 43 us per GiB per direction; the single flush costs nanoseconds. The error arm would discard the returned tuple, so the counts flush from both arms — otherwise a reset-heavy workload reports zero bytes forever.
One asymmetry is deliberate: for a -l forward the client owns the bind, so the client exports the series and the server exports none (it has no spec to name). The server’s half of a -l forward shows only as its own qqt_target_dial_failures_total, which is correct — the target is what the server knows.
The deflate context is reused across scrapes rather than rebuilt. A fresh encoder allocates about a third of a megabyte in nine calls and hands it back to an allocator that then trims the heap, so the next scrape faults those pages back in — measured, that page-fault tax was the large majority of the call. Reuse takes a gzip scrape from ~147 us to ~55 us with no minor faults at all.
The two are independent switches. --enable-metrics opens the endpoint and --stats writes the line; either one arms the shared sampler (the tick that derives bandwidth from byte deltas and jitter from the rtt window, both of which the line reports). An operator watching a terminal owes no listener; a scraper owes no log line; a box that wants both names both.
Cadence and lifecycle
- 10 s default,
--stats SECSto change it. It reads as live to a human without turning an unrotated log into a disk problem (a ~330-byte line at 10 s is under 3 MB/day), and it stays far under journald’s rate limit.--stats 0is refused: it would print as fast as the writer allows. - One line at startup, after the role’s own startup lines, so a
--statsrun says what it is before the first interval elapses — the same role/remote/version/cc identity the endpoint’sqqt_infocarries. - One line on clean exit, marked
final=1, so a run’s closing numbers are in the log without a reader having to remember the last tick. Every path that returns successfully emits it — a signal on either role, a signal during the initial connect, and the server’s endpoint closing — and it is ordered behind the last sampler tick, so nothing follows it. A crash, aSIGKILL, or a failure exit prints nothing: absence is a signal, but a weak one, because the client’s contracted loss exit (status 1 the moment the connection dies — instructions_qqt-howto.md §6) is not a fault and also ends without a marker.
Cadence is the operator’s dial, not the tunnel’s: the sampler ticks at 1 Hz regardless (SAMPLER_SECS), so a 60 s stats line still reports a fresh one-second bandwidth rate and a fresh jitter window. The line is printed from the sampler’s own tick rather than a timer beside it — two independent 1 Hz timers drift through each other, and at --stats 1 that drift re-prints a sample the tick had not refreshed.
Where this leaves the Prometheus endpoint
Untouched and complemented. --enable-metrics remains the pull interface a scraper wants, with the same numbers and the same zero-packets-on-the-wire property. --stats is the zero-infrastructure view for the far more common case: a human on a box, with a terminal and no collector, asking what the tunnel is doing. The endpoint’s scrape-is-the-liveness-verdict property is unchanged and still the reason no second health path exists.