Monitoring
fennec-server counts every statement it answers and serves the counts to Prometheus, with a Grafana dashboard ready to load.
Turn it on
Give --metrics an address and a token, and point Prometheus at
/_metrics there. Counts cover every request, reads and
writes apart, with how long each took.
# /_metrics on a listener of its own, away from the data's
fennec-server --file data.fennec --http 127.0.0.1:8080 \
--metrics 0.0.0.0:9464 --admin-token "$SCRAPE" --slow-ms 100
curl -H "Authorization: Bearer $SCRAPE" http://127.0.0.1:9464/_metrics
# fennec_statements_total{kind="read"} 1834
# fennec_statement_duration_seconds_bucket{kind="read",le="0.001"} 1790
# fennec_documents{collection="people"} 90000
# ...- With
--http, the HTTP listener serves/_metricstoo. - A scrape needs a token: the server's (
--http-token) or the admin one (--admin-token). - With
--tls-certthe--metricslistener speaks HTTPS too, with the same certificate, so a scrape's token never travels in the clear. The Prometheus job setsscheme: https, andtls_config: { ca_file: ca.pem }for a private CA (HTTPS). - Datadog, New Relic, Elastic, Grafana Cloud read the same metrics and logs: Datadog and other monitoring systems.
Which token a scrape needs
With --http the HTTP listener serves /_metrics
as well, and a --dir node serves it there. The path carries an
underscore, as /_admin and /_replication do: a
collection may well be called metrics, and
GET /metrics is how its rows are read. Prometheus takes the path
as metrics_path.
A scrape needs the server's token (--http-token) or the admin
token (--admin-token); with neither and no JSON Web Tokens the
server is open, and so are its metrics. A JWT is not taken: a user held to a
policy must not learn the other collections' names from a scrape. A
--metrics address outside loopback wants one of the two tokens,
as the HTTP listener does, or --insecure.
What is counted
Each statement is counted as a read or a write, with its latency as the client saw it. Collections, memory, replication and tenants are reported as gauges.
| Metric | Type | What it says |
|---|---|---|
fennec_statements_total{kind} | counter | statements answered; kind is read or write |
fennec_statement_errors_total{kind} | counter | statements answered with an error, the client's (a typo, a 404) or the server's |
fennec_statement_duration_seconds{kind} | histogram | arrival to answer, in buckets from 100 µs to 10 s |
fennec_slow_statements_total | counter | statements over --slow-ms, each also in the log |
fennec_bound_runs_total | counter | runs of statements bound to writes: one for each row a binding ran for. No label names a binding; /_stats/statements counts each by name |
fennec_bound_refused_total | counter | writes a bound statement refused: its guard, a wake grant the token lacked, a limit or a unique value its body met |
fennec_scheduled_runs_total{outcome} | counter | runs of scheduled statements, each counted once by how it ended: ran, refused, broken, held (the server's state holds the slot back: a tenant's quota, a lapsed lease, a storage error) or unknown (it landed as its lease lapsed, or its fsync failed: whether the file, or the tenant's next primary, holds it is unknown). Exposed once the process's scheduler made a look: a server that never held a schedule shows none of the four |
fennec_scheduled_skipped_total | counter | slots passed over: a server down for a day runs the latest missed slot once and counts the others here |
fennec_scheduled_mark_ahead_total | counter | a last mark or a definition's time found ahead of the clock, each also the audit log's clock line |
fennec_scheduled_lateness_seconds | histogram | how late a run began past its slot, in buckets from 0.1 s to a day (0.1, 0.5, 1, 5, 10, 30, 60, 120, 300, 600, 900, 1 800, 3 600, 7 200, 21 600, 86 400 s). A held slot's tries are not counted; its eventual run is. No label of the four names a tenant, a statement or a collection |
fennec_hook_events_total{outcome} | counter | webhook events that verified, each counted once by how it was answered: taken, ignored (no condition took it), replayed (its key kept), conflict (another body under a kept key), refused (by a statement, a binding or its own typing), deferred (a 429, 500, 503 or 507 its sender's retry may meet otherwise) or unknown. Exposed once a hooks file was read; no label names a hook |
fennec_hook_unverified_total{check} | counter | events answered the one 401 before their signature verified, by the check that failed: header, scheme, stale, size, hook or signature — with the log and the audit line, the one place the check is named. Not counted in fennec_refused_total, which is tokens' |
fennec_request_rate_refused_total | counter | requests refused 429 for their scoped caller's --request-rate, before anything of them ran (Requests a second): rising, a client asking past the bound, or a bound set below what an app asks |
fennec_refused_total | counter | requests refused for their token (401), each also in the audit log |
fennec_connections | gauge | connections open now, subscriptions among them; a scrape is not one. On a file's server a subscription that streams is counted under --http-max-streams, not --max-connections, so this may pass the ceiling by that many; on a tenant node, or at --http-max-streams 0, every one of them is under it |
fennec_connections_refused_total{reason} | counter | connections answered 503 with Retry-After as they were taken, never served: ceiling, past --max-connections; no_thread, the process could make no thread for one — at its thread limit (systemd's TasksMax=, a cgroup's pids.max, ulimit -u, macOS's 2 048 a process), said in the log a minute apart at most. Any no_thread is worth an alert |
fennec_tls_handshakes_failed_total{reason} | counter | connections to an HTTPS listener (--tls-cert) that ended before their handshake did: timeout, none within 10 s; closed, the client left first, a TCP health check among them; alert, the client sent one, most often because it does not trust the certificate; protocol, bytes that are not TLS or no version, cipher suite or ALPN protocol in common; plain_http, a plain request, answered 400. Said in the log a minute apart at most. A rising alert after a certificate change is worth an alert |
fennec_client_timeouts_total{reason} | counter | connections ended because their client was too slow, by the bound it ran past (Limits): header, a request not come within --header-timeout of its first byte and a second more for each KiB that came, answered 408 (over HTTPS a first record not whole is ended with nothing written); idle, a request gone silent part way for --idle-timeout, answered 408; write, an answer or a stream its client took nothing of for --write-timeout (a stream for its own bound). A connection quiet between requests is closed uncounted. A rising header with no rise in traffic is a client holding connections open on purpose; one from many clients after a release, a bound too tight for their links |
fennec_documents{collection} | gauge | documents in a collection |
fennec_data_bytes{collection}, fennec_dead_bytes{collection} | gauge | live records, and the overwritten and deleted ones compact gives back |
fennec_file_bytes, fennec_reclaimable_bytes | gauge | the file as written, and what a compact would give back of it now: the dead records, a record's head a write, the graph records a server appended in the tail; --auto-compact runs one once it passes its share (Compaction) |
fennec_auto_compactions_total | counter | compacts the server ran on its own, every file it serves together |
fennec_auto_compactions_refused_total | counter | compacts the server tried on its own and was refused, each refusal that stands logged once (Compaction) |
fennec_memory_bytes | gauge | what the process holds of the database and --max-memory counts: the indexes, and the documents too where the file is not mapped (--no-mmap) |
fennec_change_sequence | gauge | the last write's sequence number; its rate is the writes per second |
fennec_storage_failed | gauge | 1 once the disk refused a write: writes stop until the file is reopened, reads go on |
fennec_vectors_unlinked | gauge | vectors the open left out of the graph after a crash: near measures each one until a thread beside the queries has linked them, and the gauge falls to 0; on a --dir node, the open tenants' together |
fennec_replicas | gauge | on a primary, the replicas streaming from it |
fennec_replica_connected, fennec_replica_behind | gauge | on a replica: whether it hears its primary, and the writes on the primary's disk it has not applied |
fennec_replica_lag_seconds | gauge | on a replica: how old, by its primary's clock, the writes it holds were as it last read the stream, and once nothing has come for 3 s how old they are now. Writes waiting in the sockets between the two — sent as the primary sees them, unheard of as the replica does — count here and not in fennec_replica_behind, which counts writes from what the stream last said of the primary's disk: a replica reading slower than its primary writes can read 0 writes behind while it is seconds behind (Replication) |
fennec_replica_last_contact_seconds | gauge | since the primary was last heard from, a keep-alive included |
fennec_replica_images_total, fennec_replica_reconnects_total | counter | whole images taken, and connections made again |
fennec_tenants, fennec_tenants_open, fennec_tenants_disk_bytes | gauge | on a --dir node: tenants on disk, open, and their files together |
fennec_copies_disconnected, fennec_copies_behind | gauge | on a --dir node: of the copies it holds that a failover may promote — a standby's, a tenant's replica of its own, never a read replica's — how many are not connected to their primary now or have no follower running — their database failed, or nothing follows for them; a node keeps such a copy open, and after a restart counts one nothing follows for once something opens it — and the most writes on its primary's disk one has not applied, as its primary says every 2 s. A failover promotes a copy where it stands, so one counted here loses what it was not sent (watching a standby); never by tenant, whose own are at /t/<tenant>/_replication/status |
fennec_copies_lag_seconds | gauge | on a --dir node: the longest any of those copies trails its primary in time, as fennec_replica_lag_seconds counts it — writes in the sockets between them included |
fennec_build_info{version}, fennec_start_time_seconds | gauge | the version running, and when the process started |
What a statement's count includes
A statement is timed from its arrival to its answer: the wait for the lock
is in it, and under --sync always the wait for the disk, since
that is the latency a client sees. A statement is a request, and
/batch is one however
many statements it carries. A statement that took the write lock is a write,
so a get sent through POST /query is a read.
A tenant node counts its tenants and not what they hold: a tenant's
collection names are not the node's to publish, and a label per tenant would
be as many series as there are customers. The statement counters are one set
per process, and start again at zero with it, which rate() takes
in its stride.
Grafana
The repository's monitoring/ folder runs fennec-server with
Prometheus and Grafana and the dashboards already loaded: the server's
metrics, and the database's own rows through fennecdb's data source plugin
and through the Infinity plugin.
# tokens of 32 bytes: the server listens on the compose network, past loopback
export FENNEC_HTTP_TOKEN=$(openssl rand -hex 32) FENNEC_METRICS_TOKEN=$(openssl rand -hex 32) \
FENNEC_JWT_SECRET=$(openssl rand -hex 32)
docker compose -f monitoring/docker-compose.yml up -d --build
# metrics: http://127.0.0.1:3000/d/fennecdb data: http://127.0.0.1:3000/d/fennecdb-data-plugin
# Prometheus: http://127.0.0.1:9090- The metrics go fennec-server → Prometheus → Grafana, behind the
admin token: the dashboard is
grafana/fennecdb.json. - The data goes Grafana → the
fennecdb-datasourceplugin →POST /query, each panel a FennecQL statement with the time range and variables bound as its parameters, under a token that reads two collections and writes nothing, with an alert rule over the same rows: Grafana.
The dashboard's panels and alert expressions
monitoring/ in the repository holds a Grafana dashboard
(grafana/fennecdb.json), a Prometheus configuration and a compose
file that runs fennec-server with both, the dashboard already loaded. The
same compose seeds a site's events and a week of trades and loads the data
dashboards (grafana/fennecdb-data-plugin.json and
grafana/fennecdb-data.json) beside it.
It opens on the figures that decide whether anything needs doing — the
version and uptime, whether the disk has refused a write, statements and
errors per second, the memory footprint — then statements by
kind with their p50 and p99, errors, and slow statements a minute; documents,
writes a second and each collection's dead share, the one that says when to
compact; replication; tenants; and a router's requests, its
latency beside its nodes', the nodes it could not reach, the tenants on each
node and its moves. The instance variable picks one server or all of them.
Imported on its own, the dashboard asks for a Prometheus data source.
# the p99 of reads, over five minutes
histogram_quantile(0.99, sum by (le) (rate(fennec_statement_duration_seconds_bucket{kind="read"}[5m])))
# worth an alert
fennec_storage_failed == 1
fennec_replica_behind > 10000
fennec_replica_lag_seconds > 5
fennec_copies_disconnected > 0
fennec_dead_bytes / (fennec_data_bytes + fennec_dead_bytes) > 0.5fennec_replica_lag_seconds compares the two machines'
clocks by the messages that waited behind no write: the hello that opens the
stream, and the keep-alives a primary sends after two seconds with nothing
to send, never one of them alone where an earlier one is at hand. A clock
stepped on either side is followed within 20 seconds of a stream that has
nothing to send, or at the second keep-alive after a busy spell. At a
reconnect a step forward is followed at once, and a step back at the first
keep-alive after it, or, on a primary written more often than every two
seconds, which sends none, at the second reconnect. While the stream stays
busy no such message comes, so a step reads as lag (or hides as much of it)
until then; run NTP on both machines. A hello or keep-alive held up on its
way makes the figure read short by its own delay, for as long as the stream
stays busy behind it, where it is the only one to compare by — on a
replica's first connection after each start, until its first keep-alive —
and two held up that confirm each other make it read short by the lesser
of their delays (Replication, under the
status).
Slow statements
--slow-ms 100 logs every statement that took 100 ms or
longer, with what it ran, as a JSON line on stderr.
{"at":"2026-10-05T09:30:12.310Z","event":"slow","level":"warn","proto":"http","peer":"10.0.0.7:53112","request_id":"9f2c41d07ab35e18","duration_ms":312.408,"kind":"read","failed":false,"statement":"POST /query {\"query\":\"get people select name order name collate tr\"}"}What a slow-statement line holds
The log line uses the same timing the histogram has. It is the audit
log's shape — at, event, level, the
peer and the request id — with the duration in
milliseconds, whether the statement wrote (kind), whether it
failed, the tenant on a tenant node, and the statement, so one parser reads
both logs (Datadog and other monitoring
systems). --slow-ms 0 logs every statement, as PostgreSQL's
log_min_duration_statement = 0 does.
A parameter's value is not logged, only how many there were: a value bound
as $1 stays out of the log, a literal written into the text does
not. Over HTTP the line is the method and the target, and for
/query and /batch the body that holds the
statements. A line is cut at 1 000 bytes, so a bulk put of a
megabyte shows what it was without being all of it.
A named statement's call
— POST /_call/<name>, or a lone call over
/query — is logged as its shape,
"statement":"call transfer $1", never an argument, and with
"version":[history, change], the definition that ran, as
statements lists it. Its span's
db.stored_procedure.name is the statement's name.
A request that woke statements
bound to its writes adds bound: each binding it woke, its
version as statements lists it, and the rows it ran for. The
duration is the request's, which holds the bindings' runs.
{"at":"2026-10-05T09:31:40.870Z","event":"slow","level":"warn","proto":"http","peer":"10.0.0.7:53114","request_id":"1c7e5a90d2b4f683","duration_ms":148.213,"kind":"write","failed":false,"statement":"POST /query {\"query\":\"set orders {status: 'paid'} where batch = 7\"}","bound":[["paid_ledger",[3,41],12]]}A run of a scheduled
statement is logged when its time under the write lock passes
--slow-ms, never for how late it began. Its
statement is the shape schedule <name>, its
kind write, and failed is true where it
was refused or held. scheduled is [name, [history,
change], slot, rows]: the definition that ran as
statements lists it, the slot it ran for and the rows its last
statement answered, as in "scheduled":["tick",[0,4],"2026-11-03T03:00:00Z",1].
The line adds tenant on a tenant node, bound where
the run's writes woke bindings, and the run's own request_id; it
counts in fennec_slow_statements_total.
An event a webhook consumer took is a request
like any other, and is logged when the request passes --slow-ms.
Its statement is the route, POST /_hooks/stripe,
its kind write. hook is [hook,
[[name, [history, change], rows], ...]]: the hook, then each
statement that ran, its version as statements lists it and the
rows its last statement answered — 0 for the one that refused
the event. The line holds neither the event's key, its body nor a secret;
an event refused or held back, and a copy that came with another body, is
also a line of the server's log naming its key under the same
request_id.
{"at":"2026-11-07T09:31:40.870Z","event":"slow","level":"warn","proto":"http","peer":"10.0.0.7:53114","request_id":"1c7e5a90d2b4f683","duration_ms":12.408,"kind":"write","failed":false,"statement":"POST /_hooks/stripe","hook":["stripe",[["stripe_paid",[0,4],1]]]}What each statement cost
Statements are also grouped by shape — the same text with other values is
one line — with call counts, times, rows and failures, at
/_stats/statements.
curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8080/_stats/statements
curl -X DELETE -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8080/_stats/statementsHow statements are counted by shape
Every statement is also counted by its shape — its text with each literal
and parameter written $1, $2… and a list of literals
alone, a vector's components, as one — so the same statement run with other
values is one line: how often it ran, its total, mean, least and most time,
the rows it returned or changed, and its failures. Over HTTP a
/query or /batch is counted as its FennecQL; a call
to a collection's path as its method and path. A request held by
Fennec-Wait is
one call of its shape, its time every run's but not the wait, and its rows
the run that answered it: a run before that wrote nothing and was put back,
so the rows a held /batch's reads returned in it, answered to
no one, are not counted. GET
/_stats/statements answers JSON, most time first, and
DELETE forgets it all.
The server keeps at most 5 000 shapes, as PostgreSQL's
pg_stat_statements does by default,
and forgets the least called when it is full. The counts need what reads the
data without a JWT's scope, or the admin token: a shape names every
collection. A tenant node keeps each tenant's apart —
/t/<tenant>/_stats/statements — and lists every
tenant's, named, to its admin alone.
Each statement bound to
writes is a shape of its own, after paid_ledger: its calls
are the statements that woke it, its rows the rows it ran for, its time its
runs' and its errors the writes it refused. The writer's own shape holds the
binding's time too, so an operator tuning a slow set orders sees
what of it was the ledger. It is read with the rights every shape is.
Each run of a scheduled
statement is a shape of its own, schedule lapse_holds: its
calls are the runs (each try of a held slot too), its rows what its last
statement answered, its time the time under the write lock, and its errors
the runs refused, broken, held or of an unknown outcome. A client's text
that reads the same — a schedule lapse_holds sent to
/query, a parse error — is counted as a shape of its own,
never among the runs. On a tenant node a run is its tenant's
shape, at /t/<tenant>/_stats/statements, and the admin
token's /_stats/statements names every tenant's. The bindings a
run woke are counted as after <name>, as for any write.
Each statement an event of a webhook ran is a
shape of its own, hook stripe_paid: its calls are the events it
ran for, its rows what its body's last statement answered, as a call's, its
time its body's, and its errors the events it refused — its guard, a taken id
or unique value, a bound, a binding its writes woke that refused — and,
counted against each statement with no rows, an event that failed to land
after they ran. A statement before the one that refused counts the rows it
wrote, though the refusal put them back. The request's own shape, POST /_hooks/stripe, is counted too and
holds that time. A client's text that reads the same — hook
stripe_paid sent to /query — is a shape of its own, never
among the runs. On a tenant node it is the tenant's shape, at
/t/<tenant>/_stats/statements, and the admin token's
/_stats/statements names every tenant's. An event answered from
its key, taken by no condition or answered 401 runs no statement and counts
none. A hook no secret arms answers its events so: its listing says
"armed":false (Watching
them), and on a node the router's
fennec_router_tenants_hooks_behind counts the tenants whose copy
lacks the set.
The audit log
--audit <path> appends a JSON line for every refused
request, schema change and admin action. Ordinary reads and writes are
not logged.
fennec-server --file data.fennec --http 0.0.0.0:8080 \
--http-token "$TOKEN" --audit /var/log/fennec/audit.log- Refused tokens are slowed down, from 100 ms doubling to 5 s per
address, an IPv6 one's /64 (
--auth-delay). - No literal reaches the log: a schema change is logged by its shape.
- Readable by the server's user alone: on Linux and macOS the log
is made mode
0600whatever the umask, and a log there keeps its mode. A shipper running as another user is given it once, bychmodor an ACL on the file itself: a directory's default ACL does not reach it (Files on a shared machine).
The audit log's events and the refusal wait
{"at":"2026-10-01T09:30:12.310Z","event":"schema","level":"info","proto":"http","peer":"10.0.0.7:53112","request_id":"5d0e7c2a91f4b366","statement":"create collection notes (title text)","failed":false}
{"at":"2026-10-01T09:32:05.117Z","event":"refused","level":"warn","proto":"http","peer":"198.51.100.4:40031","request_id":"b81f03c6d2e94a57","method":"GET","path":"/notes","reason":"the token has expired"}
{"at":"2026-10-01T09:40:00.550Z","event":"admin","level":"info","proto":"http","peer":"10.0.0.2:61200","request_id":"deploy-7","method":"POST","path":"/_shard/tenants/acme/move","http_status":200}--audit <path> appends one JSON line for each of these
events:
- An HTTP request refused for its token (401), its
reasonthe check that failed as the 401 says it -- an expired token, another issuer or audience -- never a value the token holds. - A statement that changes the schema:
create,drop,alterorcompact. The statement is logged by its shape, as/_stats/statementsshows it, so no literal it held reaches the log. The line of acreate statement ... after, its replacement or itsdrop statementcarriesbound_collectionandbound_events("orders","set or del"): a drop's text does not say what it bound. The line of a scheduled statement's definition or replacement carriesschedule, its clause as written ("at '0 3 * * mon-fri' in 'Europe/Berlin'"), whose texts the shape made parameters. - A scheduled statement's last run found ahead of the clock: a
clockline (warn), once a statement and mark, naming thedatabase, thestatement, themark, theclock,ahead_msandwaits-- whether its slots wait for the clock to pass the mark, ahead by an hour at most, or the schedule goes on from the clock, the mark taken for a wrong clock's. A clock stepped back behind a run is one of its two readings wrong, which an operator wants to know. - A bound statement's
refusal of a scoped writer's write. The writer is told the status and
the guard's
reasonalone; aboundline holds thebinding, the engine's words aserror, themethod, thepathand thehttp_status. A write refused for lacking thewakegrant writes anunwokenline, with thebindingand areason(Waking a bound statement). The token of either checked out, so neither adds to the wait below. - A request to
/_admin/or/_shard/that changes something, with its status.fennec-shardtakes--auditas well. A query across tenants (POST /_shard/query) is one too: it reads every tenant's rows, which is what an audit log is kept for. The read it sends each node (POST /_admin/tenants/<t>/query) is not, or one query over a thousand tenants would be a thousand lines; it carries the router's request id, which the router's line names. - A read of a tenant's webhook
secrets (
GET /_admin/tenants/<t>/hook-secrets, which the router asks as it copies a set onto a copy that lacks it): ahook_secretsline naming the tenant, never a secret. Setting or taking away a hook is an admin request's line, its path naming the tenant and the hook, never its body. - A promotion forced past its node's refusal: a
failover_forcedline at the router naming the node, and apromote_forcedline at each node naming the tenant and, inoverrode, the refusal it went past (see automatic failover).
Each line has the time, a level (warn for a refusal,
info otherwise), the protocol, the peer's address and the
request id; an admin request's status is
http_status, since a log collector takes a
status for the line's level. Reads and
writes are not logged, so the
log costs nothing on their path. Lines are written as the events happen and
are not synced: after a crash the log can lose its last lines, but the data
loses nothing.
A refused token waits before it is answered, the way PostgreSQL's
auth_delay works. The first failure from an address within a
minute waits --auth-delay (100 ms by default). Each further
failure from that address doubles the wait, up to 5 s. This applies to every
401, logged or not. A guessing client gets about one try every five seconds
per address. A request whose token the server verifies — its
--http-token, a JWT whose signature checks, the admin,
replication or scrape token, a router's own --token — waits
for nothing and clears its address's count, whatever the answer then says
of the rest of the request. Nothing else clears it: an answer given without
looking at a token — an unknown path, /_health, a preflight,
the studio's files, a body over the ceiling, every answer of a server that
asks for no token — leaves the count where it was, whatever
Authorization the request carried. The count is the
address's, not a token's: a client that holds one good token clears its
count with it. Behind fennec-shard the router waits out a
refusal itself, keyed by its client's address, and the node waits none for
what the router forwards: counted at the node, every client had the
router's address, four forged tokens in a row made a fifth client's expired
one wait 1.6 s, and any good token from anyone cleared the attacker's
count. The node knows a forwarded request by a mark the router derives
from the node's --admin-token, sent beside the client's address
(Fennec-Router: <address> <mark>); the router drops
the header from what a client sends, and a node believes it from no one
else. Its audit log names the client as peer and the router as
via. The router holds no keys: the node tells it, in its
answer, that it verified a forwarded request's token, and the router clears
its client's count on that alone. Behind the global entry every client reaches a
router from Cloudflare's addresses; a router started with the entry's token
(--entry-token) takes the address the entry names in
Fennec-Client for the request's, its mark checked and its time
within a minute, and counts, clears, logs (peer, the entry as
via) and names that address onwards. An IPv4 client is one
count however it arrives: a listener on [::] sees it as
::ffff:a.b.c.d, counted as a.b.c.d. An IPv6 client
is counted by its /64, since it may send from any address of the /64 its
network was given. The
server keeps 10 000 counts, and past them lets the one refused longest ago
go, never all of them at once. Behind another reverse
proxy every client has the proxy's address, so the proxy's own rate limit
is the one that counts there. --auth-delay 0 turns the wait
off.
The router
fennec-shard serves its own /_metrics, behind its
--token: requests, the time its nodes took, failed nodes and
tenant moves. No label names a tenant.
curl -H "Authorization: Bearer $SHARD_TOKEN" http://127.0.0.1:8090/_metrics
# fennec_router_requests_total{route="tenant",code="2xx"} 48120
# fennec_router_upstream_duration_seconds_bucket{le="0.001"} 47655
# fennec_router_upstream_errors_total{node="n2"} 3
# ...| Metric | Type | What it says |
|---|---|---|
fennec_router_requests_total{route, code} | counter | requests answered; route is tenant (/t/…, forwarded), call (/t/…/_call/…, a tenant's named statement called by its path, forwarded too, never by its name), shard, replication, metrics or other, code the status class, 2xx to 5xx, or gone: a request held at its node (Fennec-Wait) whose client reset its connection, answered nothing. A client gone with its end — most timeouts and aborts — reads as one that half-closed and still reads, so its request is answered as the node answers it and counted by that status |
fennec_router_request_duration_seconds{route} | histogram | arrival to answer, in buckets from 100 µs to 10 s |
fennec_router_upstream_duration_seconds | histogram | a forwarded request's time at its node: from its sending to the whole answer. Taken from the request's duration, it leaves the router's own |
fennec_router_upstream_errors_total{node} | counter | forwarded requests a node did not answer or broke off -- answered 503 with Fennec-Unsent where the request never went out whole, 502 where the node may have run it: the one to alert on |
fennec_router_refused_total | counter | requests refused for their token (401): the router's own, and its nodes' it passed on |
fennec_router_open_node_refusals_total | counter | requests refused (403) because their tenant's node asks no data token while the router listens past loopback without --insecure — anyone on the network would have read and written that node's tenants through it (an open node behind a router). Above zero, give the node --http-token or --jwt-keys |
fennec_router_entry_clients_total{outcome} | counter | with --entry-token, what the router made of the global entry's name for the client (Fennec-Client) of each request no other router relayed: named, the address taken for the request's; bad_mark, not the entry's mark (another token, or a client sending the header itself); stale, the entry's mark made more than a minute from the router's clock; absent, a tenant's request carrying none — a client reaching the router itself, or an entry with no ENTRY_TOKEN, which names nobody. All but named count by the connection's address |
fennec_router_moves_total{outcome} | counter | tenant moves that began, done or failed and thawed; one refused before it began is not one |
fennec_router_move_duration_seconds | histogram | how long a move that was done took, the tenant frozen for all of it, in buckets from 10 ms to 1 000 s |
fennec_router_fanouts_total{outcome} | counter | queries across tenants: done, every tenant answered; partial, some failed and the caller asked for the others' rows; failed, answered with the tenants that failed; refused as a whole, before or after the asking (a request that does not read, a bound passed) |
fennec_router_fanout_duration_seconds | histogram | a query across tenants from its arrival to the merged answer |
fennec_router_fanout_tenants_total{outcome} | counter | the tenants those queries asked, answered or failed; no label names a tenant |
fennec_router_connections | gauge | client connections open now, the scrape's own among them |
fennec_router_connections_refused_total{reason} | counter | client connections the router answered 503 with Retry-After as it took them, as a node's fennec_connections_refused_total: ceiling or no_thread. A node's own refusal reaches the client as the node's 503, its request never run |
fennec_router_tls_handshakes_failed_total{reason} | counter | client handshakes the router saw fail, by the reasons of a node's fennec_tls_handshakes_failed_total |
fennec_router_client_timeouts_total{reason} | counter | client connections the router ended because the client was too slow, by the reasons of a node's fennec_client_timeouts_total: its own 408 for a request not read in time, nothing sent on to a node, or a write to the client, a relayed stream's too, that took nothing for its --write-timeout |
fennec_router_nodes, fennec_router_tenants{node, region} | gauge | the nodes in the directory, and the tenants placed on each; region where the node names one (Regions), as on every gauge by node below |
fennec_router_replicas{node, region} | gauge | the replicas of their own each node holds, with --replicas; a node's count falls to 0 after a failover took the node's replicas away, until POST /_shard/replicas |
fennec_router_same_zone_copies{region} | gauge | tenants whose replica or standby copy is in their primary's zone, so a datacenter lost takes both: placed there only where the region had no node free in another zone |
fennec_router_tenants_unreplicated{region} | gauge | with --replicas, the tenants with no copy a failover could promote — no replica of their own and no standby on their node — every region a node names, 0 or not: an attach that did not take, tried again for about four minutes (Replicas of their own); the replicas a failed-over node held, until it answers again or POST /_shard/replicas; a region with no other node. A standby router counts its primary's directory |
fennec_router_files_left | gauge | files the router may have left on nodes — made, or meant to be taken off, and placed by nothing: a create taken back whose DELETE its node refused, a copy that stayed — which every repair lists under left with why (Replicas of their own). A repair has the node take back each one noted with an identity that the file still carries, and forgets it, so the gauge falls; the rest — a copy of a deleted or detached tenant, an old primary on a node silent at the look, anything on a node from before identities, a file its node says is another now — an operator looks at and removes by hand. A standby router counts its primary's directory |
fennec_router_tenants_hooks_behind | gauge | tenants a copy of which — its primary, a pair's standby, a --replicas copy — lacks the version of their webhook secrets the directory records: a copy the router could not reach, or read the set back from, as a secret was set, or one a repair found lacking it, asking each copy its version — a node that put its set away as it started — until the repair copies the set from one holding it. Promoted so, the tenant's hooks answer 401 until their secrets are set again. A standby router counts its primary's directory |
fennec_router_tenants_moving | gauge | tenants a move began on and did not record done — served from where they were, and cleared by moving them again |
fennec_router_following | gauge | 1 on a standby router; its directory's fennec_replica_* gauges follow, and a primary's fennec_replicas |
fennec_router_lease_age_seconds{node, region} | gauge | with --auto-failover, the seconds since each node last took its lease: renewed every third of a lease, and failed over past the lease and a tenth |
fennec_router_node_failed_over{node, region} | gauge | 1 for a node the router failed over on its own and that has not answered since; 0 again once it does and a repair has its copies follow |
fennec_router_auto_failovers_total{outcome} | counter | nodes failed over on their own, done when every tenant was promoted, failed when one was not |
fennec_router_promotions_total{copy} | counter | copies of tenants a failover promoted, by whether the copy was connected to its primary as its promotion began: connected, not_connected — every copy of a node whose process was killed among them, its stream ended with it, so the router's line for the tenant, which gives how long before the copy last heard from its primary and how far behind it was, tells one cut off long before from one its node's end cut off — and unknown, a node too old to say. A copy stays connected until a read of its stream fails, 10 s on where its primary's machine was lost or cut off: the line says what it was not sent is lost wherever it was last heard from more than 4 s before. What a copy promoted was not sent is lost |
fennec_router_cut_requests_total{outcome} | counter | requests out to a node as a failover — by hand or on a lease — moved their tenant off it, ended at once rather than left to wait for --upstream-timeout (Requests out to a node failed over): sent_again to the tenant's new primary, the node having run nothing or the request being a read or a keyed write; may_have_run, a write sent whole with no key, answered 502; stream_ended, a subscription ended for its client to open again. Each is counted in fennec_router_requests_total as well, by the status it was answered with; none is an upstream error |
What the router counts
fennec-shard serves /_metrics on its own listener,
behind its --token as /_shard/ is: a scrape names the
nodes. It counts what it answered and what the nodes took over it; what a
tenant's statements did is its node's to count, and no label names a tenant.
A request is timed from its arrival to its answer, the node's time included —
a subscription to its head, since the stream lasts as long as its client
stays; a standby router's replication stream is counted and not timed. A
request is counted before its answer is written, as a node counts its
statements, so a client holding its answer finds it in the next scrape; its
time ends once the answer is written.
# what the router adds, at the median, over five minutes
histogram_quantile(0.5, sum by (le) (rate(fennec_router_request_duration_seconds_bucket{route=~"tenant|call"}[5m])))
- histogram_quantile(0.5, sum by (le) (rate(fennec_router_upstream_duration_seconds_bucket[5m])))
# worth an alert
rate(fennec_router_upstream_errors_total[5m]) > 0
fennec_router_tenants_moving > 0
increase(fennec_router_auto_failovers_total[5m]) > 0
fennec_router_node_failed_over > 0
fennec_router_same_zone_copies > 0
# tenants with no copy to fail over to, on the router keeping the directory
fennec_router_tenants_unreplicated > 0 and on (instance) fennec_router_following == 0
# files the router may have left on nodes, that a repair could not take back
fennec_router_files_left > 0 and on (instance) fennec_router_following == 0
# behind the global entry: a token or a clock to fix, or an entry naming
# nobody (its ENTRY_TOKEN unset) -- on a router only the entry reaches
rate(fennec_router_entry_clients_total{outcome=~"bad_mark|stale"}[5m]) > 0
rate(fennec_router_entry_clients_total{outcome="absent"}[5m]) > 0
# tenants by region
sum by (region) (fennec_router_tenants)Request ids
Every answer carries an X-Request-Id, and every line its
request wrote — the audit log's, the slow statement's, an error on stderr —
carries the same id. A client's own id is kept; one is made where none was
sent.
curl -si -H 'X-Request-Id: checkout-7f3a' http://127.0.0.1:8080/_health | grep -i request-id
# X-Request-Id: checkout-7f3aHow a request id is kept or made
An id a client sends is kept when it is printable ASCII of at most 128
bytes; any other is replaced, as a header or a log line could not carry it
whole. A made one is 16 hex characters. fennec-shard takes the
client's id or makes one, sends it to the node, which takes it as its own,
and answers with it: one request through the router has one id in the
router's log, the node's and the answer. A text line on stderr written while
a request was served — a sync error — ends with
request_id=<id>. A subscription's and a replication
stream's head carry the id too. Making one and writing it cost a request
nothing measurable (make requests-bench, in turns).
Tracing
With --otlp-endpoint, fennec-server and fennec-shard send
OpenTelemetry traces: a span a request, with its waits under it — the
lock, the statement, the disk, the replicas. Any system that takes OTLP
shows where a request's time went: Datadog, Grafana Tempo, Honeycomb, New
Relic, Elastic.
# an OpenTelemetry Collector, or the Datadog Agent, on this host
fennec-server --file data.fennec --sync always \
--otlp-endpoint http://127.0.0.1:4318 --trace-sample 0.1
OTEL_SERVICE_NAME=orders-db fennec-server --file data.fennec \
--otlp-endpoint http://127.0.0.1:4318- A collector on loopback. The endpoint is usually a collector on the same host or network — the OpenTelemetry Collector, the Datadog Agent's OTLP receiver, Grafana Alloy — which forwards over TLS: their setup.
- Or an
https://endpoint. It is dialed over TLS, its certificate held to Mozilla's roots or to--tls-ca's CAs in their place (Dialing HTTPS). A port left out is 443, and a refused certificate sends no span. - W3C
traceparent. A request carrying one continues the caller's trace;fennec-shardcontinues it and hands it to the node, so the router's spans and the node's are one tree. - Off unless an endpoint is given, and free when off. A ratio samples the traces that start at fennecdb; a caller's sampled trace is always followed.
| Span | Kind | What it times |
|---|---|---|
POST /query, GET /{collection}, POST /t/{tenant}/batch… | server | the request, from its head read to its answer written: its method and route, never a value |
lock.wait | internal | the wait for the database's lock, fennec.lock read or write: a read waits out a write's block, a write every read |
execute | internal | the statement run, under the lock; a /batch's statements together, fennec.statements of them, and a create index or compact beside the database with fennec.beside |
bound <name> | internal | a bound statement's runs for one statement of the request, a child of the request's span: db.operation.name bound, db.stored_procedure.name its name and fennec.rows_woken the rows it ran for, never a row's value. The one that refused the write is marked failed with the status it answered and its else's reason (412 no ledger line), error.type the status: never the engine's words, which may hold a row's value |
schedule <name> | internal | a scheduled statement's run, the root of a trace of its own: its children are lock.wait, execute, durability where the run landed, and a bound <name> for each binding its writes woke. Its attributes follow the table |
hook <name> | internal | a statement a webhook event ran, a child of the event's request span: db.operation.name hook, db.stored_procedure.name its name and fennec.rows the rows its last statement answered. The one that refused the event is marked failed with its status and the reason its else wrote (412 no open order of that total), error.type the status: never the engine's words |
durability | internal | a write's wait for the disk after the lock (--sync always); on a primary it holds fsync and replication.wait_sent, the wait for its replicas' streams to send the write |
fennec.wait_for_write | internal | a replica's wait for the write a Fennec-After names |
forward | client | fennec-shard's forward to the node, to its whole answer: the node's server span is its child |
The span's attributes and how spans are sent
The server span carries OpenTelemetry's names where one fits:
http.request.method, http.route (a template:
/t/{tenant}/{collection}/near), url.path,
http.response.status_code, server.address and
server.port, client.address — the client behind
a router, or behind the global entry where a router believes it — and the
connection's own address as network.peer.address,
db.system (fennecdb),
db.operation.name (get, put,
create…) and, for FennecQL, db.query.text — the
statement's shape, each literal and parameter written $n, as
the statements' counts show it, so no value
reaches a span. A REST request's target holds values in its query string,
so it has its route alone. A --dir node's and the router's
spans carry fennec.tenant, the router's fennec.node,
and every server span fennec.request_id, the
request id its log lines carry. A 5xx marks the
server span an error; a 4xx is the client's and does not.
A run of a scheduled
statement is no request, so it is a trace of its own: sampled at
--trace-sample, begun and ended on the scheduler's thread, which
never waits on the collector. The root span schedule <name>
carries db.system (fennecdb),
db.operation.name (schedule),
db.stored_procedure.name (the statement), db.query.text
(schedule <name>), fennec.slot (the slot, an
ISO timestamp), fennec.lateness_ms, fennec.slots_skipped,
fennec.outcome (ran, refused,
broken, held or unknown),
fennec.request_id (the run's own id, the one its log lines
carry) and fennec.tenant on a tenant node. A refused or held
run's span is marked failed with its status and the reason its
else wrote (412 no tick at the epoch),
error.type the status: never the engine's words, which may hold a
row's value. A run whose outcome is unknown is failed as 500, as
a client's write would be answered.
An event of a webhook is its request's trace.
Its server span, POST /_hooks/{name} or POST
/t/{tenant}/_hooks/{name}, templates the hook's name as
{name} in http.route whatever word it is. It
carries db.operation.name hook,
fennec.hook (the hook's name) and fennec.outcome:
taken, ignored, replayed,
conflict, refused, deferred or
unknown, the outcomes fennec_hook_events_total
counts. Each statement the event ran is a child span, hook
<name> in the table. No span holds the event's key or a value of
its body.
A request's traceparent is read as the W3C spec writes it;
one that does not parse starts a trace of its own, and
tracestate goes on unchanged. A trace starting at fennecdb is
kept when its id's low 56 bits fall under the ratio, OpenTelemetry's
TraceIdRatioBased, so a router and its nodes sampling at one
ratio keep the same traces. --trace-sample is 1 with an
endpoint; a busy server wants less. Health checks, scrapes, preflights and
the studio's files are no spans, and a subscription or a replication
stream, which lasts as long as its client, has none.
The endpoint is taken from --otlp-endpoint, then
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, both used as given unless
they name no path, then OTEL_EXPORTER_OTLP_ENDPOINT, under
which /v1/traces goes. --otlp-header k=v (and
OTEL_EXPORTER_OTLP_HEADERS) adds a header to every post, an
API key a collector asks for; OTEL_SERVICE_NAME names the
service (fennec-server, fennec-shard) and
OTEL_RESOURCE_ATTRIBUTES adds to it. Spans go as OTLP over
HTTP with JSON, POST /v1/traces with
application/json, the collector's port 4318: an
OTEL_EXPORTER_OTLP_PROTOCOL of grpc is refused
at the start rather than sent to a port that cannot read it.
A finished request's spans go into a queue of
OTEL_BSP_MAX_QUEUE_SIZE spans (2 048), and a thread of their
own posts it every OTEL_BSP_SCHEDULE_DELAY (1 s), or as soon
as OTEL_BSP_MAX_EXPORT_BATCH_SIZE (512) are in, a post at
most that many, each bounded by OTEL_EXPORTER_OTLP_TIMEOUT
(10 s) and kept alive between posts. A request never waits for the
collector: with the queue full its spans are dropped and counted, and a
post that fails drops its spans, logged once a minute at most. fennec-server posts the
last second's spans as it shuts down.
| Metric | Type | What it says |
|---|---|---|
fennec_trace_spans_exported_total | counter | spans the endpoint took |
fennec_trace_spans_dropped_total{reason} | counter | spans left out: queue_full, the collector not keeping up, or export_failed, a post refused or unanswered |
What it costs
Counting is close to free: a few nanoseconds a statement, and counting one by its shape takes a fraction of the time parsing it does.
What counting and tracing cost, measured
Counting a statement is a handful of relaxed atomic adds, into counters a
thread each: 6.7 ns a statement with eight threads counting at once. Into one
shared set of counters the same eight cost 720 ns each, the cache line moving
from core to core, which is why they are spread. The router counts a request
the same way, 13.3 ns with eight threads counting, beside the 17 µs it adds
to the request (make shard-bench). A scrape reads the gauges
under the database's shared lock, beside the readers and ahead of a writer
for as long as a count would be.
Tracing off is one relaxed atomic load at each hook: in
make requests-bench, six runs in turns against the server
without it, one client's round trip stayed 0.022, 0.033, 0.059 and 0.021
ms at the median for a row by id, a filter, a near and a put,
against 0.022, 0.034, 0.059 and 0.022, and eight clients' requests a second
inside the runs' own spread. On, every request sampled, to a collector on
the same machine: 0.022, 0.034, 0.060 and 0.024 ms, and eight clients 2 to 9%
fewer requests a second — the exporter's thread writing 250 000 spans a
second as JSON took a core of the eight the clients and the server shared.
A sampled request's spans cost it their timestamps and a few allocations;
the JSON and the post are the exporter's.
Counting it by its shape is a pass over its text into a buffer the thread
keeps, and an entry found in the thread's shard: 0.34 µs for a read of 87
bytes, 0.56 µs with eight threads counting at once — a sixth of the 2.2 µs
parsing it takes. It grows with the text: 5.6 µs for a near with
768 components written into it, whose parse takes 85
(make statements-bench). A shape is made only as far as the
1 000 bytes kept of it, so two statements alike that far are one line: shaped
whole, a put of 1 000 rows of 128-dim vectors spent 1.7 ms of
its 12.6 there.