Metrics: what GET /metrics returns¶
Every qix rank serves Prometheus text at GET /metrics on its HTTP port
(csrc/server/http_server.cpp:1182). The node router serves one GET /metrics for the whole host,
merged from its copies (csrc/distributed/node_router.cpp:1906). Both answer with
Content-Type: text/plain; version=0.0.4; charset=utf-8.
When a rank records request metrics (see
When a rank renders no request metrics), seven of its
families use vLLM's names, labels and bucket bounds. A Prometheus query written for one of those
seven reads qix too. A dashboard written for vLLM shows only the panels built on those seven: qix
does not emit vLLM's other families (the list is under
Request metrics, vLLM names). The other qix families start with
tnd_.
A host without the tnd-metrics group and the /run/tnd directory records no request metrics, so
its ranks emit none of the vllm: families. Only the .deb packaging creates those two. Such a
rank still emits the token counters and the out-of-memory counters.
/metrics has no authentication. See trusted-network.md.
Terms used on this page:
- Rank: one
python -m tnd.serveprocess. - Copy: one rank (or lockstep group of ranks) behind the node router; its index is its place in the router's list of upstreams, starting at 0.
- Node router:
tnd-node-router, the front endqix-servestarts when it runs more than one copy on a host.
Per rank¶
A rank's body has three parts, in this order (csrc/server/http_server.cpp:1186-1187):
- token counters (
render_window_prometheus); - out-of-memory counters (
ServeLoop::oom_prometheus); - request metrics under vLLM's names (
render_request_prometheus).
Request metrics, vLLM names¶
Rendered by render_request_prometheus (csrc/server/prom_render.cpp:133). Every vllm: series
carries engine="0" and model_name="<served model id>".
| Family | Type | Extra labels | Meaning | Line |
|---|---|---|---|---|
vllm:time_to_first_token_seconds |
histogram | le |
time from the HTTP handler's start to the first token | csrc/server/prom_render.cpp:146 |
vllm:request_time_per_output_token_seconds |
histogram | le |
per request: (last token time - first token time) / (tokens - 1) | csrc/server/prom_render.cpp:148 |
vllm:e2e_request_latency_seconds |
histogram | le |
time from the HTTP handler's start to the last token | csrc/server/prom_render.cpp:151 |
vllm:num_requests_running |
gauge | requests in the running batch | csrc/server/prom_render.cpp:154 |
|
vllm:num_requests_waiting |
gauge | requests accepted and not yet placed in a batch | csrc/server/prom_render.cpp:156 |
|
vllm:kv_cache_usage_perc |
gauge | 1 - free blocks / total blocks; 1 means full. Cached blocks that can be evicted count as free | csrc/server/prom_render.cpp:161 |
|
vllm:request_success_total |
counter | finished_reason = stop or length |
requests that finished. A request that ended in tool calls counts under stop, because vLLM has no tool_calls reason |
csrc/server/prom_render.cpp:171 |
The three histograms count successful requests only. The bucket bounds are vLLM's
(csrc/server/engine_metrics_page.h:119, csrc/server/engine_metrics_page.h:129, csrc/server/engine_metrics_page.h:138).
These seven are the only vllm: families the server writes. vLLM families that qix does not
emit:
| vLLM family | What qix has instead |
|---|---|
vllm:prompt_tokens_total, vllm:generation_tokens_total |
tnd_input_tokens_total, tnd_output_tokens_total (below) |
vllm:prefix_cache_queries, vllm:prefix_cache_hits |
tnd_prefix_cache_block_queries_total, tnd_prefix_cache_block_hits_total, counted in blocks, not tokens |
vllm:inter_token_latency_seconds |
nothing: qix keeps one mean per request (vllm:request_time_per_output_token_seconds), not every gap between tokens |
vllm:request_queue_time_seconds, vllm:request_inference_time_seconds, vllm:request_prefill_time_seconds, vllm:request_decode_time_seconds |
nothing |
vllm:request_prompt_tokens, vllm:request_generation_tokens, vllm:iteration_tokens_total |
tnd_prompt_length_tokens for prompt length; nothing for the other two |
vLLM's abort, error and repetition values of finished_reason are not rendered either.
Request metrics, qix names¶
These carry model_name only.
| Family | Type | Meaning | Line |
|---|---|---|---|
tnd_kv_blocks_total |
gauge | KV blocks in this rank's pool | csrc/server/prom_render.cpp:180 |
tnd_kv_blocks_free |
gauge | KV blocks that are free or hold only evictable cached content | csrc/server/prom_render.cpp:183 |
tnd_prefix_cache_block_queries_total |
counter | prefix-cache lookups, counted in blocks | csrc/server/prom_render.cpp:187 |
tnd_prefix_cache_block_hits_total |
counter | lookups that found a cached block, in blocks | csrc/server/prom_render.cpp:190 |
vLLM's vllm:prefix_cache_queries and vllm:prefix_cache_hits count tokens. qix counts blocks, so
its families keep a tnd_ name. Hit rate is hits / queries in either case.
To get a host's KV usage from several ranks, sum the block gauges:
1 - sum(tnd_kv_blocks_free) / sum(tnd_kv_blocks_total). Averaging vllm:kv_cache_usage_perc
over ranks gives the wrong answer when pools differ in size.
When a rank renders no request metrics¶
A rank that does not record request metrics writes one comment line in place of the families above
(csrc/server/prom_render.cpp:134):
- a tensor-parallel rank above rank 0. Rank 0 serves the HTTP API for the group, so scrape rank 0.
- a rank started with
TND_ENGINE_METRICS_ENABLED=0. - a rank on a host where it cannot set up its metrics page
(
csrc/server/engine_metrics_page.cpp:278-307). That happens when any of these is missing: - a group named
tnd-metrics(csrc/server/engine_metrics_page.h:32). The rank gives the page file to that group. - the
/run/tnddirectory, writable by the rank. The page file is/run/tnd/engine-metrics.v1(csrc/server/engine_metrics_page.h:31). - a readable process start time in
/proc/self/stat.
Packaged build only. The .deb package creates the tnd-metrics group, and its systemd
units create /run/tnd. Nothing in the open source tree creates either one.
So on a host that has neither, a build from source, a pip install, python -m tnd.serve and
qix-serve run by hand all record no request metrics: their /metrics holds the token counters, the out-of-memory counters
and the comment line, and no vllm: series, no tnd_kv_blocks_* gauge and no
tnd_prefix_cache_block_* counter. The rank logs one of three lines
(csrc/server/engine_metrics_page.cpp:278-307):
- [tnd-metrics] group tnd-metrics missing; engine metrics disabled, inference unaffected
- [tnd-metrics] cannot read process start ticks; engine metrics disabled, inference unaffected
- [tnd-metrics] page setup failed for /run/tnd/engine-metrics.v1; engine metrics disabled,
inference unaffected
The comment line it writes in /metrics still names only the two cases above.
When no copy records request metrics, the node router writes no tnd_node_kv_cache_usage
(csrc/distributed/node_router_metrics.h:322).
No zero-valued gauge is written in that case, so a missing series means "not recorded", never "zero".
Token counters¶
Rendered by render_window_prometheus (csrc/server/prom_render.cpp:56). Each carries
model_name. Every one counts since the process started.
| Family | Type | Extra labels | Meaning | Line |
|---|---|---|---|---|
tnd_input_tokens_total |
counter | prompt tokens of successful requests, prefix-cache hits included | csrc/server/prom_render.cpp:61 |
|
tnd_cached_input_tokens_total |
counter | the part of those prompt tokens the prefix cache served | csrc/server/prom_render.cpp:65 |
|
tnd_output_tokens_total |
counter | tokens generated for successful requests | csrc/server/prom_render.cpp:69 |
|
tnd_stats_requests_total |
counter | outcome = ok or failed |
finished requests | csrc/server/prom_render.cpp:73 |
tnd_prompt_length_tokens |
histogram | le |
prompt length of successful requests, in tokens | csrc/server/prom_render.cpp:80 |
tnd_distinct_prompt_openings |
gauge | estimate (about 3.3 % error) of distinct prompt openings (the hash of each prompt's first 128 tokens) | csrc/server/prom_render.cpp:92 |
Tokens per minute over a window is the change in tnd_input_tokens_total plus the change in
tnd_output_tokens_total, divided by the window's minutes.
Out-of-memory counters¶
Rendered by ServeLoop::oom_prometheus (csrc/server/serve_loop.cpp:2795). These have no labels.
| Family | Type | Meaning |
|---|---|---|
tnd_forward_oom_total |
counter | steps whose model forward ran out of GPU memory; the server kept serving |
tnd_forward_oom_requeued_rows_total |
counter | rows of those steps put back in the waiting queue |
tnd_forward_oom_failed_rows_total |
counter | rows of those steps that failed |
Refused requests¶
When a rank records request metrics (see
When a rank renders no request metrics), every request
that ends, refused ones included, is counted in a fixed table of terminal slots, one
counter per outcome (csrc/server/engine_metrics_page.h:69). The slot for a request refused because the
queue was full is kFailedQueueFull, with the label error_code="503"
(csrc/server/engine_metrics_page.h:76, labels at csrc/server/engine_metrics_page.h:101). A request
whose stated deadline passed while it waited takes error_code="timeout". A request refused
because the rank was stopping, draining or asleep takes error_code="engine_unavailable".
On this release, /metrics renders three of the four success slots, in two samples of
vllm:request_success_total (csrc/server/prom_render.cpp:172): finished_reason="stop" is the sum
of the stop and tool_calls slots, and finished_reason="length" is the length slot. The fourth
success slot, unknown, is counted but not rendered. No failure slot is rendered, so a queue-full
refusal does not appear in any /metrics family:
- it is not in
vllm:request_success_total; - it is not in
tnd_stats_requests_total{outcome="failed"}, because a request refused at submit never enters the engine.
A request that was queued and then timed out on its deadline does count in
tnd_stats_requests_total{outcome="failed"} (csrc/server/serve_loop.cpp:1552,
csrc/server/serve_loop.cpp:3442).
On the copy that owns it, the slot counters live in the engine metrics page, a shared-memory file at
/run/tnd/engine-metrics.v1 (csrc/server/engine_metrics_page.h:31). The page layout is a fixed
ABI that an external reader can map read-only.
In a launch of several copies, only the first copy to create /run/tnd/engine-metrics.v1 owns it.
The other copies keep their slots in a private page in process memory, which only their own
/metrics reads (csrc/server/engine_metrics_page.cpp:293-322). /metrics renders no failure
slot, so the queue-full counts of those copies cannot be read anywhere on this release.
After a restart, no live copy may own the file. The engine never removes the page file
(csrc/server/engine_metrics_page.cpp:411-415). In the packaged build the tnd-server@ unit sets
RuntimeDirectoryPreserve=yes, so /run/tnd and the old file survive when tnd-server@
instances restart. A copy that finds a file left by an earlier instance gets the same "file exists"
error and takes a private page, like a second copy (csrc/server/engine_metrics_page.cpp:294-301).
The file then holds the dead instance's numbers, and no copy's slot counts can be read outside its
own process. The copy logs [tnd-metrics] /run/tnd/engine-metrics.v1 already exists (another copy
owns it) in both cases.
The HTTP answer for each refusal is in operations.md.
Node router¶
The router's GET /metrics asks every copy not marked dead for its /metrics, each on its own
thread, and merges the answers into one body (csrc/distributed/node_router.cpp:1906). Each copy
is asked with the router's connect timeout and probe timeout (5 s + 1.5 s by default,
csrc/distributed/node_router.h:339, csrc/distributed/node_router.h:340). These timeouts apply
per connect and per read, not to the whole answer. When no thread can be started, the router asks
the copies one after another (csrc/distributed/node_router.cpp:1929), so the scrape then takes
longer with more copies. It answers during start-up too.
How a copy's series are labelled¶
The merge (merge_copy_metrics, csrc/distributed/node_router_metrics.h):
- A series with an
enginelabel gets the copy index as its value:engine="2"is copy 2. This is what vLLM's data-parallel front end does: one series per engine, not summed. - A series with no
enginelabel getstnd_copy="<index>"added. - Each family's
# HELPand# TYPEappear once, and its series stay together in copy order. - Other comment lines are dropped, including the "not recorded" line of a tensor-parallel rank above 0. A sample line that does not parse is dropped and counted.
The router's own families¶
Written after the copies' families. All are gauges.
| Family | Labels | Meaning | Line |
|---|---|---|---|
tnd_router_copies_total |
copies behind this router | csrc/distributed/node_router_metrics.h:301 |
|
tnd_router_copies_scraped |
copies whose /metrics answered and are in this body |
csrc/distributed/node_router_metrics.h:303 |
|
tnd_router_copies_dead |
copies marked dead by the health probe, not asked | csrc/distributed/node_router_metrics.h:305 |
|
tnd_router_copies_failed |
copies asked that gave no 200 in time |
csrc/distributed/node_router_metrics.h:307 |
|
tnd_router_copy_scraped |
tnd_copy |
1 when that copy's series are in this body, else 0 | csrc/distributed/node_router_metrics.h:313 |
tnd_router_metric_lines_dropped |
sample lines that did not parse, in this scrape | csrc/distributed/node_router_metrics.h:315 |
|
tnd_node_kv_cache_usage |
1 - sum(free) / sum(total) of the copies' tnd_kv_blocks_* gauges |
csrc/distributed/node_router_metrics.h:325 |
|
tnd_node_kv_copies |
scraped copies that reported both block gauges | csrc/distributed/node_router_metrics.h:331 |
tnd_node_kv_cache_usage is written only when every scraped copy reported its block gauges, so a
figure for part of the host never carries the host's name. When it is missing,
tnd_node_kv_copies is less than tnd_router_copies_scraped.
Check tnd_router_copies_scraped against tnd_router_copies_total before you sum a host's
counters: a copy that did not answer is missing from that scrape, and a counter summed across a
gap looks like a drop.
Scrape targets¶
- One rank, no router: scrape the rank's port.
- Several copies on one host: scrape the router's port. Do not also scrape the rank ports, or each series is counted twice.
- Tensor-parallel group: scrape rank 0.