Repository navigation
API: Add opt-in /metrics endpoint with live generation counters - #510
Merged
Merged
Conversation
Closed
Generation counters advance as each piece is delivered to the client, on a per-request clock, so a scraper sees throughput while a request runs. Same option, endpoint and metric names as theroyallab#443. Off by default; when off, the generation loop makes no metrics calls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
blaakstone
force-pushed
the
feature/live-metrics
branch
from
October 30, 2026 20:35
26e0f00 to
04c4643
Compare
turboderp
added a commit
that referenced
this pull request
Nov 1, 2026
DingoOz
pushed a commit
to DingoOz/llm-visuals
that referenced
this pull request
Nov 25, 2026
TabbyAPI (ExLlamaV2/V3) was only named in the keyword list, with no live numbers. Since theroyallab/tabbyAPI#510 it serves an opt-in Prometheus /metrics (network.enable_metrics) with llama.cpp-style names under a tabbyapi: prefix. Detect `python main.py` / `start.py` launches that name tabby or exllama, read the port, host, model name and max_seq_len from the YAML --config (port 5000 otherwise), and recognise the tabbyapi: samples behind --endpoint. Map the counters onto the shared vLLM adapter: prompt, cached and generated tokens, requests in flight, TTFT, server-measured decode time and the draft counters, with the draft depth taken as drafted tokens per verify step. The cached and verify-step counters also accept the names of an earlier draft of the endpoint. Tested on an RTX 5090 against tabbyAPI main with ExLlamaV3 and MTP: live decode, depth 6, acceptance matching the server's own figure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Is your pull request related to a problem? Please describe.
The
/metricsendpoint in #443 accumulates its counters from the backend'sfinish chunk, so
tabbyapi:tokens_predicted_totalandtabbyapi:tokens_predicted_seconds_totalonly move when a request completes.During a long generation a scraper sees nothing for tens of seconds and then a
single step, which leaves a throughput graph with nothing to plot.
This adds the same endpoint with those counters written as each piece is
delivered to the client, so they move while the model is generating.
Why should this feature be added?
Live throughput is what a dashboard wants. llama.cpp and vLLM update their
token counters while a request is in flight, so a dashboard polling a mixed
deployment shows a flat line for tabbyAPI until each request ends. The endpoint
stays opt-in (
network.enable_metrics, off by default, no API key required,like
/health). When it is off, the generation loop skips the per-piece calls:the only cost on a request is one config read.
Examples
One 2000-token streaming completion, polled every 2 s:
tokens_predicted_totalwent 142 → 411 → 685 → 940 → 1167 → 1378, withpredicted_tokens_secondsat 120-130 tokens/s andrequests_processingat 1throughout.
rate(tabbyapi:tokens_predicted_total[10s])therefore shows thegeneration while it runs instead of one step afterwards.
Checked against the responses: for a 500-token completion the counter moved by
exactly 500, and four queued 300-token completions moved it by 1200. With MTP
speculative decoding (6 draft tokens) the counters reported 3042 drafted, 1006
accepted and 507 decode steps. With
max_batch_size: 1, four simultaneousrequests showed
requests_processing 1/requests_deferred 2while queued,and 0 / 0 once drained. Disabled, the endpoint answers 404 with a message naming
the option.
Additional context
Builds on #443 by
klement: the option name, the endpoint path, the404-when-disabled behaviour, and the metric names and help text are the same, so
a scraper written for that PR works unchanged. This is a stand-alone subset (the
inference counters only: no KV-cache, offload, recurrent-cache or histogram
metrics) and does not depend on #443. If both land, the two
common/metrics.pyneed reconciling; the per-piece calls here can be carried over to #443.
Generation tokens are counted as they are delivered (
len(token_ids)of eachpiece, on a per-request clock), not read from the engine's
new_tokenson thefinish chunk. This stays correct when one piece carries several tokens (the
streaming merge from #450), but the total can differ by a token from the
engine's own tally.
Tested with
pytest tests/test_metrics.py tests/test_metrics_endpoint.py(9 tests, no GPU), and on a 27B EXL3 model on a single RTX 5090, including a
dashboard (llm-visuals with a tabbyAPI adapter) that now shows throughput during
the generation. Not covered: the cancellation path. In my test, killing the
client did not stop the generation, so the request still finished and was
counted.
formatting.shcurrently exits early onmain: it checks ruff's versionagainst
requirements-dev.txt, which is no longer in the repository. This PRwas formatted with
ruff formatandruff checkdirectly (the version pinnedin
pyproject.toml).Written with the help of a language model, reviewed and tested on real hardware.