Sub topic 14
Monitoring a running server
This chapter assumes you can start vllm serve and call it with the OpenAI client. It also assumes you know what the KV cache, prefill, decode, and continuous batching are from earlier chapters. You do not need prior Prometheus experience, but the basic idea helps: a service exposes numbers over HTTP, and a collector reads them on a schedule.
Why a vLLM server needs its own metrics
CPU and GPU utilization graphs tell you little about an LLM server. A GPU can show 100% utilization while users wait ten seconds for a first token. The real limits are the KV cache and the scheduler, so you need metrics that show:
- how many requests are being served and how many are queued,
- how full the KV cache is,
- how long users wait for the first token and for each later token,
- how many tokens the server processes per second.
vLLM exposes all of these on the /metrics endpoint of the same HTTP port as the API. The format is plain Prometheus text, so no extra process is needed.
Reading the endpoint
Start a server as in the earlier chapters, then read the endpoint and keep only the vLLM series:
curl -s http://localhost:8000/metrics | grep '^vllm:'Each series name starts with vllm:. Lines beginning with # are HELP and TYPE comments, and the grep removes them. Many series carry labels such as model_name="Qwen/Qwen2.5-1.5B-Instruct".
Metric names change between vLLM versions. For example, the KV cache usage gauge was vllm:gpu_cache_usage_perc in older releases and is vllm:kv_cache_usage_perc in newer ones. Always run the curl command above against your own version before you write dashboards or alerts.
The metrics that matter
Prometheus has three metric types, and they behave differently:
- A gauge is a value that goes up and down, such as the number of waiting requests.
- A counter only increases, such as total tokens generated. You read it as a rate.
- A histogram records how many observations fell into each value range (bucket). It also keeps a running
_sumand_count, so you can compute averages and percentiles.
| Series (typical name) | Type | What it tells you |
|---|---|---|
| `vllm:num_requests_running` | gauge | Requests in the current batch. Bounded by `max_num_seqs`. |
| `vllm:num_requests_waiting` | gauge | Requests queued because the batch or cache is full. |
| `vllm:kv_cache_usage_perc` | gauge | Fraction of KV cache blocks in use, from 0 to 1. |
| `vllm:num_preemptions_total` | counter | Requests evicted from the cache and later recomputed. |
| `vllm:prompt_tokens_total` | counter | Prefill tokens processed. |
| `vllm:generation_tokens_total` | counter | Tokens generated. Its rate is your decode throughput. |
| `vllm:time_to_first_token_seconds` | histogram | Time from arrival to first token (queueing plus prefill). |
| `vllm:e2e_request_latency_seconds` | histogram | Total time per request. |
| `vllm:request_success_total` | counter | Finished requests, labeled by finish reason. |
The time-to-first-token histogram is the best signal for how responsive the server feels. A per-token latency histogram is also exposed. Its name varies by version, for example vllm:time_per_output_token_seconds or vllm:inter_token_latency_seconds.
How the pieces connect
Scraping with Prometheus
Prometheus pulls from /metrics; the server never pushes. A minimal scrape configuration looks like this:
global:
scrape_interval: 5s
scrape_configs:
- job_name: vllm
metrics_path: /metrics
static_configs:
- targets: ["localhost:8000"]A short interval such as 5 seconds is useful for LLM traffic, because queues can build and drain within a minute. Rates and percentiles are then computed in PromQL, Prometheus's query language. Three useful queries:
rate(vllm:generation_tokens_total[1m])
vllm:num_requests_waiting
histogram_quantile(0.95, sum by (le) (rate(vllm:time_to_first_token_seconds_bucket[5m])))The first gives generated tokens per second. The second shows the queue depth. The third gives the 95th percentile time to first token over five minutes. Use percentiles, not averages: a handful of slow requests can hide behind a good mean.
A quick check without Prometheus
For a smoke test or a script, you can parse the endpoint directly. This example uses the prometheus_client package (pip install prometheus-client) and reads a few key numbers:
from urllib.request import urlopen
from prometheus_client.parser import text_string_to_metric_families
URL = "http://localhost:8000/metrics"
text = urlopen(URL).read().decode()
values = {}
for family in text_string_to_metric_families(text):
for s in family.samples:
if s.name.startswith("vllm:"):
values[s.name] = values.get(s.name, 0.0) + s.value
for name in (
"vllm:num_requests_running",
"vllm:num_requests_waiting",
"vllm:kv_cache_usage_perc",
"vllm:gpu_cache_usage_perc",
):
if name in values:
print(f"{name}: {values[name]:.3f}")
total = values.get("vllm:time_to_first_token_seconds_sum")
count = values.get("vllm:time_to_first_token_seconds_count")
if total is not None and count:
print(f"mean time to first token: {total / count:.3f}s over {int(count)} requests")The script prints whichever cache-usage name your version provides. The mean is computed over the server's whole lifetime, so it is only a rough check. Use rate() in Prometheus for current behavior.
Reading the signals together
Single numbers mislead. Read them as patterns:
- Waiting requests above zero while running requests sit at
max_num_seqs: the batch limit is the bottleneck. Raisingmax_num_seqsmay help if the cache has room. - Waiting requests above zero while KV cache usage is near 100%: memory is the bottleneck. Lower
max_model_len, raisegpu_memory_utilization, quantize, or add GPUs. - Preemptions increasing: the cache ran out while requests were mid-generation, so vLLM evicted some and recomputes them later. This costs latency. Treat a steadily rising preemption rate as a sign of an undersized cache.
- Time to first token rising while generation throughput stays flat: requests are queueing, or long prompts are slowing prefill.
- Cache usage low but latency high: the cause is probably not memory. Check prompt lengths, the network, and the client.
Alerting
Start with a few alerts tied to user impact, not to every metric:
- Queue depth:
vllm:num_requests_waiting > 0for several minutes. - Latency: p95 time to first token above your target.
- Cache pressure: cache usage above about 95% for several minutes, combined with preemptions.
- Availability: the scrape itself failing, which Prometheus records as
up == 0.
Common mistakes
- Using a metric name from a blog post or older docs without checking it on your version. A dashboard panel that silently shows "no data" is the usual symptom.
- Graphing counters directly. A counter only climbs, so wrap it in
rate(). - Averaging latency histograms. Use
histogram_quantilefor percentiles. - Testing with idle traffic. Idle metrics show nothing useful, so generate load first. The next chapter covers benchmarking for that purpose.
- Running several replicas without a per-instance label. Add the instance name in the scrape config so each server can be compared.
Exercise
Your dashboard shows vllm:numrequestswaiting at 40, vllm:numrequestsrunning steady at 64 (the value of maxnumseqs), and KV cache usage at 55%. Which setting would you change first, and why?
Show answer
Raise maxnumseqs. The batch is capped at 64 sequences while the KV cache is only 55% full, so memory is not the limit. The scheduler is refusing to batch more requests than the cap allows, which creates the queue. Raise the cap in steps and watch cache usage and preemptions, since going too high will fill the cache and cause evictions.
Exercise
Write the PromQL expression for the 99th percentile time to first token over the last 10 minutes.
Show answer
histogramquantile(0.99, sum by (le) (rate(vllm:timetofirsttokensecondsbucket[10m])))