Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Prometheus | The monitoring system that scrapes (reads) a server’s /metrics page on a timer and stores the numbers (22.j). |
| Counter | A number that only goes up, such as total tokens generated. You look at its rate over time. |
| Gauge | A number that goes up and down, such as requests waiting right now. |
| Histogram | Counts of observations in buckets (“how many took under 0.1 s, under 0.25 s, …”), from which percentiles are estimated. |
| p50 / p95 / p99 | Percentiles: the value below which 50%, 95% or 99% of observations fall. p99 is “the slow tail”. |
| TTFT / ITL / TPOT | Time to first token; inter-token latency (gap between streamed outputs); time per output token (2.c). |
| Preemption | The scheduler evicting a running request’s KV blocks to make room, and recomputing it later (17.c). |
1. What is it?#
vLLM publishes several dozen metrics at /metrics, all prefixed vllm:. They are not
independent facts. Each is produced at a specific point on the request path you have already
read, and once you know which point, the numbers explain each other:
- Latency histograms say what users experience.
- Gauges and counters about the queue, the cache and preemptions say why.
This lesson maps the important metrics to the code that produces them and ends with a five-question diagnostic procedure. Facts checked on 12 November 2026 against vLLM v0.32.0. General practice for metrics and dashboards is 22.j; the wider observability story is in the Observability learning materials.
flowchart LR A[":i-clock: arrival"] -->|"queue time"| S[":i-list-checks: first scheduled"] S -->|"prefill time"| F[":i-zap: first token"] F -->|"decode time"| L[":i-check: last token"] A -.->|"time to first token"| F A -.->|"end-to-end latency"| L Q[":i-gauge: num_requests_waiting"] -.-> S K[":i-layers: kv_cache_usage_perc<br/>num_preemptions"] -.-> S P[":i-search: prefix_cache_hits / queries"] -.-> F class A,S,F,L neutral class Q,K,P queue
2. Why does it matter?#
A slow LLM server has many possible causes: too many requests, a full KV cache, long prompts,
a slow tokenizer, prefill chunks interrupting streams, a busy CPU. They look the same to a user,
and they need opposite fixes. Raising --max-num-seqs helps one and makes another worse. The
metrics are how you tell them apart without guessing, and they are the inputs to tuning (19.d),
autoscaling (19.e) and capacity planning (23.b).
3. Simple analogy#
A hospital emergency department. “Time until seen by a doctor” (TTFT) is what patients complain about. To fix it you need the other numbers: how long people sat in the waiting room (queue time), how many beds are occupied (KV cache usage), how many patients were moved out of a bed to make room (preemptions), and how many already had their notes on file (prefix-cache hits).
4. Tiny example: one request’s clock#
t = 0.000 request arrives at the API server
t = 0.004 tokenised, sent to the engine core QUEUED event (engine clock)
t = 0.180 first scheduled SCHEDULED event
t = 0.410 first token produced
t = 4.410 last of 201 tokens produced
queue time = 0.180 − 0.004 = 0.176 s
prefill time = 0.410 − 0.180 = 0.230 s
TTFT ≈ 0.410 s (measured from arrival at the API server)
decode time = 4.410 − 0.410 = 4.000 s
TPOT = 4.000 / 200 = 20 msMost of this request’s TTFT is prefill, not queueing, so a bigger --max-num-seqs would not help.
5. Technical explanation#
Where metrics are produced#
The engine core never touches Prometheus. It attaches raw facts to its outputs, and the API server turns them into metrics in its output-handling loop (16.f):
- Each
EngineCoreOutputcarriesevents:QUEUED,SCHEDULEDandPREEMPTED, each stamped with the engine core’s monotonic clock. - Each
EngineCoreOutputscarriesscheduler_stats: running and waiting counts, KV cache usage, prefix-cache counters. IterationStatsaccumulates per-step token counts in the API server.
Two consequences. Engine-core timestamps are only ever subtracted from each other, never
compared with the API server’s clock. And with several API server processes, each sees only its
own requests; /metrics aggregates across them, and per-engine metrics carry an engine label.
The intervals#
From vllm/v1/metrics/stats.py:
queued_time = req_stats.scheduled_ts - req_stats.queued_ts
prefill_time = req_stats.first_token_ts - req_stats.scheduled_ts
decode_time = req_stats.last_token_ts - req_stats.first_token_ts
inference_time = req_stats.last_token_ts - req_stats.scheduled_tsscheduled_ts is set only the first time a request is scheduled (# ignore preemptions in
the source). A preempted request’s recomputation therefore shows up inside its prefill or decode
time, not as queue time.
| Histogram | Interval | What moves it |
|---|---|---|
vllm:request_queue_time_seconds | Engine arrival → first scheduled | max_num_seqs reached, KV cache full, a long prompt at the head of the queue |
vllm:request_prefill_time_seconds | First scheduled → first token | Prompt length, token budget, prefix hits, other prefills sharing the budget |
vllm:time_to_first_token_seconds | API server arrival → first token | Frontend time (tokenising, media) plus the two above |
vllm:inter_token_latency_seconds | Between consecutive streamed outputs | Step time: batch size, prefill chunks in the step, preemption stalls |
vllm:request_time_per_output_token_seconds | decode_time ÷ (output tokens − 1), once per request | The same, averaged per request |
vllm:request_decode_time_seconds | First token → last token | Output length × step time |
vllm:request_inference_time_seconds | First scheduled → last token | Prefill plus decode |
vllm:e2e_request_latency_seconds | Arrival → finish | Everything |
Inter-token latency records one sample per streamed output; time per output token one
sample per request. They differ whenever an output carries several tokens (speculative
decoding, or --stream-interval above 1), and they weight requests differently: a long response
contributes many samples to the first and one to the second. Use the first for a streaming
smoothness objective, the second for cost per token. --custom-histogram-buckets (new in
v0.32.0) lets you move bucket boundaries to where your objective is.
State gauges#
| Gauge | Source | Meaning |
|---|---|---|
vllm:num_requests_running | len(scheduler.running) | Requests holding KV blocks and being stepped |
vllm:num_requests_waiting | Waiting queues | Admitted to the engine, not yet running |
vllm:num_requests_waiting_by_reason | Label reason: capacity or deferred | Capacity: no slot or no memory. Deferred: skipped for now, waiting for a grammar, remote KV or a LoRA slot |
vllm:kv_cache_usage_perc | BlockPool.get_usage() = 1 − free ÷ total blocks | Share of blocks held by live requests, 0 to 1. Cached-but-free blocks count as free. |
vllm:num_requests_kv_fetch_by_stage | KV connector state (19.b) | Requests waiting for, receiving, or holding remotely loaded KV |
vllm:engine_sleep_state | Sleep mode (19.e) | Label sleep_state: awake, weights offloaded, or all discarded |
num_requests_waiting_by_reason is the quickest way to tell a saturated server from a
misconfigured one. Many waiting for capacity means more GPUs or shedding load. Many deferred
means look at grammar compilation time, --max-loras, or the KV transfer path.
Counters#
Names below are as registered in vllm/v1/metrics/loggers.py. On the wire, and in every
PromQL query, each counter carries a _total suffix added by the Prometheus client:
vllm:num_preemptions is scraped as vllm:num_preemptions_total.
| Counter | Meaning |
|---|---|
vllm:prompt_tokens, vllm:generation_tokens | Throughput, as rates |
vllm:prompt_tokens_by_source | Prompt tokens by where their KV came from: local_compute, local_cache_hit, external_kv_transfer |
vllm:prompt_tokens_cached (and _by_source) | Prompt tokens served from a cache |
vllm:prefix_cache_queries, vllm:prefix_cache_hits | In tokens. Hit rate = rate(hits) ÷ rate(queries) |
vllm:external_prefix_cache_queries, …_hits | The same for a KV connector |
vllm:num_preemptions | Running requests evicted for memory |
vllm:request_success | Finished requests by finished_reason: stop, length, abort, error, repetition |
vllm:admission_rejections | Requests refused by max_num_queued_reqs or max_num_queued_tokens (new in v0.32.0) |
vllm:mm_cache_queries, vllm:mm_cache_hits | Multimodal processor cache |
Watch finished_reason. A rising share of length means answers are cut off by max_tokens or
the context window. A rising share of abort means clients are giving up, usually because of
latency. error means a retryable internal failure, such as a failed KV load.
Request-shape histograms#
vllm:request_prompt_tokens, vllm:request_generation_tokens, vllm:request_params_max_tokens,
vllm:request_params_n and vllm:iteration_tokens_total describe your traffic rather than
your server. They feed capacity arithmetic: the p95 of prompt plus generation tokens is the
number to divide KV capacity by (17.h). vllm:request_prefill_kv_computed_tokens is prompt
tokens actually computed per request, after cache hits; its ratio to request_prompt_tokens is
your effective cache benefit. vllm:request_num_preemptions shows how often single requests are
preempted.
Optional metrics#
| Flag | Adds |
|---|---|
--kv-cache-metrics | Sampled block lifetimes: vllm:kv_block_lifetime_seconds, …_idle_before_evict_seconds, …_reuse_gap_seconds. If blocks are evicted seconds after going idle and the reuse gap is longer, a bigger cache would raise hits. |
| speculative decoding | The vllm:spec_decode_* family (18.f) |
--enable-mfu-metrics | Estimated FLOPs and bytes read and written per GPU, for utilisation dashboards |
--otlp-traces-endpoint | An OpenTelemetry span per request, with the same intervals as attributes |
--enable-per-request-metrics | The timings returned inside each API response, for billing or per-request SLAs |
--enable-logging-iteration-details | Each step’s composition in the log. Very verbose; debugging only |
The periodic log line#
Without Prometheus you still get, every few seconds while busy:
Avg prompt throughput: 5120.4 tokens/s, Avg generation throughput: 1843.0 tokens/s,
Running: 42 reqs, Waiting: 7 reqs, Preemptions: 3, GPU KV cache usage: 91.2%,
Prefix cache hit rate: 63.5%Deferred, KV fetch and Preemptions appear only when non-zero; external and multimodal cache
hit rates appear when those caches exist. --disable-log-stats turns the line off, and with it
the collection that Prometheus metrics depend on.
A diagnostic procedure#
Ask in this order. Each question either finds the problem or rules out a layer.
1. Is TTFT high because of the queue? Compare request_queue_time_seconds with
time_to_first_token_seconds.
- Queue time dominates → the server is saturated or blocked. Go to 2.
- Queue time is small → the time is in prefill or the frontend. Go to 4.
2. Why are requests waiting? num_requests_running against max_num_seqs, and
kv_cache_usage_perc.
- Running equals
max_num_seqs, cache usage moderate → the sequence limit binds. Raise--max-num-seqsif step time allows. - Cache usage near 1.0 → memory binds. Go to 3.
- Neither → head-of-line blocking by a large request, or deferred requests: check
num_requests_waiting_by_reason.
3. Is the cache thrashing? rate(vllm:num_preemptions_total[5m]).
- Sustained preemptions → over-admission. Lower
--max-num-seqs, add--watermark, lower--max-model-len, or add cache (17.c). - None → the cache is simply full of useful work. You need capacity.
4. Is prefill slow? request_prefill_time_seconds against prompt length, and the prefix hit
rate.
- Hit rate lower than the workload should give → prompt structure (17.f).
- Prefill fine but TTFT high → the frontend: tokenising, chat templates, media. Look at the API
server’s CPU, and
--api-server-count.
5. Is streaming uneven? The upper percentiles of inter_token_latency_seconds.
- p99 far above p50 → prefill chunks sharing steps with decoders. Lower
--max-num-batched-tokens, set--long-prefill-token-threshold, or disaggregate (19.b). - The whole distribution high → batch too large for the GPU, or CPU-bound: check the engine core has a full core.
6. Under the hood: quantiles from buckets#
Prometheus histograms are cumulative bucket counts, so percentiles must be estimated. This
program does what PromQL’s histogram_quantile does, on a sample scrape, and derives the ratios
that matter.
// quantiles.go — histogram_quantile by hand, on a /metrics scrape.
package main
import (
"bufio"
"fmt"
"math"
"sort"
"strconv"
"strings"
)
// A scrape of /metrics, shortened: other labels (model_name, engine) and the
// queue-time buckets above 10 s (all 3000) are left out. Bucket boundaries are
// vLLM v0.32.0's defaults; histogram buckets are cumulative. The Prometheus
// client adds "_total" to every counter name.
const scrape = `
vllm:time_to_first_token_seconds_bucket{le="0.001"} 0
vllm:time_to_first_token_seconds_bucket{le="0.005"} 0
vllm:time_to_first_token_seconds_bucket{le="0.01"} 0
vllm:time_to_first_token_seconds_bucket{le="0.02"} 5
vllm:time_to_first_token_seconds_bucket{le="0.04"} 40
vllm:time_to_first_token_seconds_bucket{le="0.06"} 120
vllm:time_to_first_token_seconds_bucket{le="0.08"} 260
vllm:time_to_first_token_seconds_bucket{le="0.1"} 480
vllm:time_to_first_token_seconds_bucket{le="0.25"} 1630
vllm:time_to_first_token_seconds_bucket{le="0.5"} 2410
vllm:time_to_first_token_seconds_bucket{le="0.75"} 2650
vllm:time_to_first_token_seconds_bucket{le="1.0"} 2790
vllm:time_to_first_token_seconds_bucket{le="2.5"} 2950
vllm:time_to_first_token_seconds_bucket{le="5.0"} 2990
vllm:time_to_first_token_seconds_bucket{le="10.0"} 2998
vllm:time_to_first_token_seconds_bucket{le="+Inf"} 3000
vllm:request_queue_time_seconds_bucket{le="0.3"} 2650
vllm:request_queue_time_seconds_bucket{le="0.5"} 2780
vllm:request_queue_time_seconds_bucket{le="0.8"} 2850
vllm:request_queue_time_seconds_bucket{le="1.0"} 2900
vllm:request_queue_time_seconds_bucket{le="1.5"} 2940
vllm:request_queue_time_seconds_bucket{le="2.0"} 2960
vllm:request_queue_time_seconds_bucket{le="2.5"} 2970
vllm:request_queue_time_seconds_bucket{le="5.0"} 2995
vllm:request_queue_time_seconds_bucket{le="10.0"} 3000
vllm:request_queue_time_seconds_bucket{le="+Inf"} 3000
vllm:prefix_cache_queries_total 9200000
vllm:prefix_cache_hits_total 5840000
vllm:prompt_tokens_total 9200000
vllm:generation_tokens_total 1150000
vllm:num_preemptions_total 14
vllm:num_requests_running 187
vllm:num_requests_waiting 23
vllm:kv_cache_usage_perc 0.94
vllm:request_success_total{finished_reason="stop"} 2610
vllm:request_success_total{finished_reason="length"} 330
vllm:request_success_total{finished_reason="abort"} 60
`
type bucket struct {
le float64
count float64
}
func parse(text string) (hist map[string][]bucket, scalars map[string]float64) {
hist, scalars = map[string][]bucket{}, map[string]float64{}
sc := bufio.NewScanner(strings.NewReader(text))
for sc.Scan() {
line := strings.TrimSpace(sc.Text())
if line == "" || strings.HasPrefix(line, "#") {
continue
}
sp := strings.LastIndex(line, " ")
name, val := line[:sp], line[sp+1:]
v, _ := strconv.ParseFloat(val, 64)
if i := strings.Index(name, `_bucket{le="`); i >= 0 {
leStr := strings.TrimSuffix(name[i+len(`_bucket{le="`):], `"}`)
le := math.Inf(1)
if leStr != "+Inf" {
le, _ = strconv.ParseFloat(leStr, 64)
}
hist[name[:i]] = append(hist[name[:i]], bucket{le, v})
} else {
scalars[name] = v
}
}
return
}
// quantile estimates q by linear interpolation inside the bucket that contains it.
func quantile(bs []bucket, q float64) float64 {
sort.Slice(bs, func(i, j int) bool { return bs[i].le < bs[j].le })
rank := q * bs[len(bs)-1].count
prevLe, prevCount := 0.0, 0.0
for _, b := range bs {
if b.count >= rank {
if math.IsInf(b.le, 1) {
return prevLe // beyond the last finite bucket: only a lower bound is known
}
return prevLe + (b.le-prevLe)*(rank-prevCount)/(b.count-prevCount)
}
prevLe, prevCount = b.le, b.count
}
return prevLe
}
func main() {
hist, s := parse(scrape)
for _, name := range []string{"vllm:request_queue_time_seconds", "vllm:time_to_first_token_seconds"} {
fmt.Printf("%-36s p50 %.3f s p95 %.3f s p99 %.3f s\n", name,
quantile(hist[name], 0.50), quantile(hist[name], 0.95), quantile(hist[name], 0.99))
}
fmt.Printf("\nprefix cache hit rate %.1f%% of prompt tokens\n",
100*s["vllm:prefix_cache_hits_total"]/s["vllm:prefix_cache_queries_total"])
fmt.Printf("prompt : generation ratio %.1f : 1\n", s["vllm:prompt_tokens_total"]/s["vllm:generation_tokens_total"])
total := 0.0
for k, v := range s {
if strings.HasPrefix(k, "vllm:request_success_total") {
total += v
}
}
fmt.Printf("finished by length %.1f%%\n", 100*s[`vllm:request_success_total{finished_reason="length"}`]/total)
fmt.Printf("aborted by client %.1f%%\n", 100*s[`vllm:request_success_total{finished_reason="abort"}`]/total)
fmt.Printf("\nrunning %v, waiting %v, KV usage %.0f%%, preemptions %v\n",
s["vllm:num_requests_running"], s["vllm:num_requests_waiting"],
100*s["vllm:kv_cache_usage_perc"], s["vllm:num_preemptions_total"])
fmt.Println("reading: median queue time is small, but its p95 and p99 are a large share of TTFT's,")
fmt.Println("KV usage is 94% and there are preemptions: the tail is caused by memory pressure.")
}Output:
vllm:request_queue_time_seconds p50 0.170 s p95 0.800 s p99 2.500 s
vllm:time_to_first_token_seconds p50 0.233 s p95 1.562 s p99 3.750 s
prefix cache hit rate 63.5% of prompt tokens
prompt : generation ratio 8.0 : 1
finished by length 11.0%
aborted by client 2.0%
running 187, waiting 23, KV usage 94%, preemptions 14
reading: median queue time is small, but its p95 and p99 are a large share of TTFT's,
KV usage is 94% and there are preemptions: the tail is caused by memory pressure.How to read it:
- The interpolation is exactly what a dashboard does, and it shows histograms’ weakness:
precision is limited by bucket boundaries. The queue-time p99 of 2.500 s is simply the upper
edge of the
le="2.5"bucket, and the p95 of 0.800 s the edge ofle="0.8". - Default buckets cannot see short queues. In v0.32.0 the queue, prefill, decode, inference
and end-to-end histograms share one bucket family (
request_latencyinvllm/v1/metrics/buckets.py) whose first boundary is 0.3 s. Every request that waited less than 300 ms lands in the same bucket, so the p50 of 0.170 s is an artefact of linear interpolation from 0, not a measurement. If your queue-time objective is below 0.3 s, set finer boundaries, for example--custom-histogram-buckets '{"request_latency": [0.01, 0.05, 0.1, 0.3, 1, 5, 30, 120]}'. TTFT has its own, much finer family, starting at 1 ms. - Counters in a real scrape are totals since start, and end in
_total. vLLM registersvllm:prefix_cache_hits, but the Prometheus client exposes it asvllm:prefix_cache_hits_total; query that name. In production take rates over a window, for examplerate(vllm:prefix_cache_hits_total[5m]) / rate(vllm:prefix_cache_queries_total[5m]), rather than dividing totals as this program does.
7. Performance implications#
- Collection is cheap but not free. Per-request stats run in the API server’s output loop.
Optional families such as
--kv-cache-metricssample to stay cheap; per-request metrics in responses carry a documented overhead warning at high concurrency. - Cardinality. Every label value is a separate time series. Per-engine labels across a large DP deployment, multiplied by LoRA adapters, multiply storage. Scrape only what you use.
- Scrape interval vs. bursts. A 30-second scrape averages away a 5-second spike. For incident analysis keep at least one fast-scraped panel on the key gauges.
8. Production implications#
- Alert on causes, page on symptoms. Page on TTFT or ITL percentiles breaking the SLO; alert
(not page) on preemption rate,
admission_rejectionsand a/healthfailure. - Autoscale on queue signals (
num_requests_waiting, queue time), not GPU utilisation (19.e). - Dashboards ship with vLLM.
examples/observability/has Prometheus and Grafana setups and an OpenTelemetry example. - Metric names change. v0.32.0 added
admission_rejections,prompt_tokens_cached_by_source,num_requests_kv_fetch_by_stageandwatermark_requests. Re-check dashboards after upgrades.
9. Common mistakes#
- Reading prefix-cache counters as request counts. They are tokens.
- Treating
kv_cache_usage_percnear 1.0 as a good thing. With preemptions, it is over-admission. - Mixing ITL and TPOT in one SLO. One is per streamed output, the other per request.
- Averaging latency. Means hide the tail users complain about.
- Turning on
--disable-log-statsfor “performance” and losing every metric. - Expecting queue time to include preemption. It does not; preempted time lands in prefill or decode time.
10. Hands-on exercise#
- Run
quantiles.go. Replace the queue-time buckets with finer custom ones (add 0.01, 0.05 and 0.1 below 0.3) and invent counts in which 95% of requests wait less than 50 ms. Rerun: how much does the estimated p50 move, and why could the default buckets not show it? - Scrape a real server twice, 60 seconds apart, and compute the prefix-cache hit rate for that window from the two pairs of counters.
- Build one dashboard panel that plots
vllm:kv_cache_usage_percandrate(vllm:num_preemptions_total[5m])together. At what usage do preemptions begin on your workload? - Start a server with
--max-num-queued-reqs 8, send 50 concurrent requests, and readvllm:admission_rejections_totaland the HTTP status codes.
11. Interview questions#
- In which process are Prometheus metrics computed, and what does the engine core contribute?
- A request is preempted once and resumes. Does its queue time increase? Where does the lost time show up?
- KV cache usage is 30% but the prefix-cache hit rate is high. Is that contradictory?
- p99 ITL is six times p50 and queue time is low. What is the likely mechanism, and which two flags address it?
- Why can a histogram’s p99 be exactly a bucket boundary?
12. Further reading#
Checked on 12 November 2026 against vLLM v0.32.0.
- Production metrics (vLLM docs)
- Metrics (design)
- Per-request metrics
vllm/v1/metrics/loggers.py— every metric definition and the log linevllm/v1/metrics/stats.py— the interval arithmetic- Prometheus and Grafana example
- Inference engine metrics (Observability learning materials)
- Prometheus: histograms and summaries