Pidoku

Metrics, Prometheus, and Dashboards

Module 22 Lesson 22.j 1h 15m Difficulty 3/5

Prerequisites 22.d, 19.c, 20.c


Before you start: words you need#

WordPlain meaning
PrometheusThe monitoring system that scrapes (reads) each server’s /metrics page every few seconds and stores the numbers as time series.
Time seriesOne metric name plus one exact set of label values, with its history. vllm:num_requests_running{model_name="chat",engine="0"} is one series.
LabelA key–value tag on a metric, such as model_name="chat". Every distinct combination of label values is a separate series.
CardinalityHow many series a metric produces: the product of the number of values of each label.
Counter / gauge / histogramA number that only goes up (total tokens); a number that goes up and down (requests waiting now); counts of observations in buckets, from which percentiles are estimated (19.c).
PromQLPrometheus’s query language. rate(x[5m]) is the per-second increase of counter x over the last five minutes.
Recording ruleA PromQL expression Prometheus evaluates on a timer and stores as a new series, so dashboards and alerts read one cheap series.
DCGM / dcgm-exporterNVIDIA’s GPU telemetry library, and the program that publishes its fields for Prometheus (22.d).

1. What is it?#

Turning the numbers an inference server already exports into a few dashboards and alerts that answer, at a glance, three performance questions:

Are users getting the latency we promised?        latency histograms
What is limiting us right now?                    queue, KV cache, preemptions, running batch
What are we paying per token, and how much        tokens per second, tokens per step,
of the hardware is doing useful work?             prefix-cache hits, aborts, DCGM DRAM_ACTIVE

This lesson owns the dashboard and alert design for performance work: which metric answers which question, the PromQL, labels and cardinality, the layout of three dashboards, and the efficiency alerts that teams forget. It builds on two neighbours and does not repeat them:

  • 19.c explains where in vLLM’s code each vllm: metric is produced and gives a five-question diagnostic procedure. Metric names here are vLLM v0.32.0 names, the same as 19.c.
  • 23.h is the service owner’s view: per-request logs, traces and OpenTelemetry’s GenAI conventions, tail sampling, paging policy and runbooks.

Facts checked on 13 November 2026.


2. Why does it matter?#

A generic web-service dashboard shows request rate, errors, latency and CPU. For an LLM server that dashboard looks healthy right up to the moment it falls over, because the real limits are invisible to it:

  • The KV cache fills before anything else. Latency stays flat until the cache is full, then preemptions start and the tail explodes. Only vllm:kv_cache_usage_perc and vllm:num_preemptions_total show it coming.
  • Queue time is half of TTFT. A rising TTFT means either “more queueing” (add capacity) or “slower prefill” (fix prompts or caching). Opposite fixes; one dashboard panel tells them apart.
  • GPU utilisation says nothing (22.d). A server can show 100% and be serving four requests.
  • Waste is silent. Tokens generated for clients who already left, low running batch on an over-provisioned fleet: nothing is slow, so nothing alerts, and the bill doubles.

Good dashboards turn the method of 22.a (“measure, find the binding limit, change one thing”) into something on-call can do in two minutes.


3. Simple analogy#

A car’s instrument panel. The speedometer (latency) is what the driver cares about. But a good panel also has the fuel gauge (KV cache usage: how much room is left), the rev counter (running batch: how hard the engine is working), the warning lights (preemptions, admission rejections) and the fuel-economy readout (cost per token). A panel with only a speedometer tells you that you have stopped, not why.


4. Tiny example: the three numbers every dashboard derives#

A dashboard is mostly arithmetic on a few series. This program does three pieces of it: how many series a label choice creates, the share of requests inside a TTFT objective (computed from one histogram’s bucket counter), and cost per million output tokens.

Go
// dashboard.go — three numbers every LLM dashboard derives: series count,
// share of requests inside the objective, and cost per million output tokens.
package main

import "fmt"

func main() {
	// 1. Cardinality: vLLM v0.32.0 TTFT histogram, 22 bucket boundaries.
	// Each label combination exports 22 buckets + le="+Inf" + _sum + _count.
	perCombo := 22 + 1 + 2
	models, engines, replicas := 3, 4, 10
	base := perCombo * models * engines * replicas
	fmt.Printf("TTFT histogram, model x engine x replica: %11d series\n", base)
	tenants := 200
	fmt.Printf("  ... plus a tenant label (200 tenants):  %11d series\n", base*tenants)
	users := 50000
	fmt.Printf("  ... plus a user label (50,000 users): %11d series\n\n", base*tenants*users)

	// 2. Share of requests inside a TTFT objective, from two counters of one
	// histogram over the same 5-minute window (per-second rates).
	under1s := 41.3 // rate(..._bucket{le="1.0"}[5m])
	all := 43.0     // rate(..._count[5m])
	fmt.Printf("TTFT <= 1 s for %.1f%% of requests (objective 99%%: %s)\n\n",
		100*under1s/all, verdict(under1s/all >= 0.99))

	// 3. Cost per million output tokens.
	gpus, dollarsPerGPUHour := 16.0, 2.50
	genTokPerSec := 9000.0 // sum(rate(vllm:generation_tokens_total[5m]))
	perM := gpus * dollarsPerGPUHour / 3600 / genTokPerSec * 1e6
	fmt.Printf("cost: %.0f GPUs x $%.2f/h, %.0f output tok/s -> $%.2f per million output tokens\n",
		gpus, dollarsPerGPUHour, genTokPerSec, perM)
	// The same fleet at half the traffic costs twice as much per token.
	fmt.Printf("same fleet at %.0f tok/s                     -> $%.2f per million output tokens\n",
		genTokPerSec/2, perM*2)
}

func verdict(ok bool) string {
	if ok {
		return "met"
	}
	return "missed"
}

Output:

TTFT histogram, model x engine x replica:        3000 series
  ... plus a tenant label (200 tenants):       600000 series
  ... plus a user label (50,000 users): 30000000000 series

TTFT <= 1 s for 96.0% of requests (objective 99%: missed)

cost: 16 GPUs x $2.50/h, 9000 output tok/s -> $1.23 per million output tokens
same fleet at 4500 tok/s                     -> $2.47 per million output tokens

Three lessons in eight lines. One extra label multiplies storage by its number of values. “Share of requests under the objective” is often more useful than a p95, and it is exact when the objective is a bucket boundary. And cost per token is a ratio: halve the traffic on a fixed fleet and it doubles, though nothing got slower.


5. Technical explanation#

The metric set, by question#

All vllm: names are from vLLM v0.32.0 (vllm/v1/metrics/loggers.py), labelled model_name and engine (the engine index, 19.a). Counters are defined without a suffix in vLLM’s code, but the Prometheus client library appends _total when it publishes them, so in a scrape and in PromQL vllm:prompt_tokens is vllm:prompt_tokens_total. Histograms appear as _bucket, _sum and _count series.

LATENCY: what users experience                         type        query with
  vllm:time_to_first_token_seconds                     histogram   histogram_quantile
  vllm:inter_token_latency_seconds                     histogram   (one sample per streamed output)
  vllm:request_time_per_output_token_seconds           histogram   (one sample per request)
  vllm:e2e_request_latency_seconds                     histogram
  vllm:request_success_total{finished_reason=...}      counter     stop, length, abort, error, repetition

CAPACITY: what limits you
  vllm:kv_cache_usage_perc                             gauge 0–1   ← the capacity signal
  vllm:num_requests_running                            gauge       the running batch
  vllm:num_requests_waiting                            gauge
  vllm:num_requests_waiting_by_reason{reason=...}      gauge       capacity or deferred
  vllm:request_queue_time_seconds                      histogram   ← the overload signal
  vllm:num_preemptions_total                           counter
  vllm:admission_rejections_total{reason=...}          counter     (new in v0.32.0)

EFFICIENCY: what you pay for
  vllm:prompt_tokens_total, vllm:generation_tokens_total     counters  throughput
  vllm:iteration_tokens_total                          histogram   tokens per engine step
  vllm:prefix_cache_hits_total / _queries_total        counters    in tokens, not requests
  vllm:prompt_tokens_by_source_total{source=...}       counter     computed, cache hit, KV transfer
  vllm:estimated_flops_per_gpu_total                   counter     only with --enable-mfu-metrics
  DCGM_FI_PROF_DRAM_UTIL_RATIO                         gauge 0–1   memory interface busy (22.d)
  DCGM_FI_PROF_TENSOR_UTIL_RATIO                       gauge 0–1   tensor pipe busy

HEALTH: the hardware under it (22.d, 23.e)
  DCGM_FI_DEV_FB_USED_BYTES, DCGM_FI_DEV_BOARD_POWER_WATTS, DCGM_FI_DEV_SM_CLOCK_HERTZ,
  DCGM_FI_DEV_GPU_TEMP_CELSIUS, DCGM_FI_DEV_XID_ERROR, DCGM_FI_DEV_ROW_REMAP_*

NOT IN THE ENGINE: emit from your gateway (23.h)
  latency by prompt-length bucket, tokens by tenant, tokens generated after the client left,
  goodput per request (both objectives met)

The DCGM names are dcgm-exporter 4.9.0’s defaults; older exporters use the pre-4.7 names listed in 22.d (DCGM_FI_PROF_DRAM_ACTIVE for the first one).

Three that teams most often fail to collect, and what each catches:

  • Running batch (vllm:num_requests_running, compared with --max-num-seqs): whether the fleet is traffic-limited. A replica averaging 12 of 256 slots is mostly idle hardware.
  • Queue time (vllm:request_queue_time_seconds): overload, before it becomes an SLO breach.
  • Aborted requests (vllm:request_success_total{finished_reason="abort"}): clients giving up, usually because of latency, and capacity spent on answers nobody reads.

The PromQL you will reuse#

PromQL
# p95 TTFT per model (sum the buckets across engines and replicas first, keep le)
histogram_quantile(0.95,
  sum by (le, model_name) (rate(vllm:time_to_first_token_seconds_bucket[5m])))

# Share of requests with TTFT <= 1 s (exact only if 1.0 is a bucket boundary)
sum(rate(vllm:time_to_first_token_seconds_bucket{le="1.0"}[5m]))
  / sum(rate(vllm:time_to_first_token_seconds_count[5m]))

# Queue time as a share of TTFT, averaged: near 1 means capacity, near 0 means prefill or frontend
sum(rate(vllm:request_queue_time_seconds_sum[5m]))
  / sum(rate(vllm:time_to_first_token_seconds_sum[5m]))

# Prefix-cache hit rate (tokens)
sum(rate(vllm:prefix_cache_hits_total[5m])) / sum(rate(vllm:prefix_cache_queries_total[5m]))

# Average tokens per engine step: how full each GPU step is
sum(rate(vllm:iteration_tokens_total_sum[5m])) / sum(rate(vllm:iteration_tokens_total_count[5m]))

# Preemptions per finished request
sum(rate(vllm:num_preemptions_total[5m])) / sum(rate(vllm:request_success_total[5m]))

# Aborted share
sum(rate(vllm:request_success_total{finished_reason="abort"}[5m]))
  / sum(rate(vllm:request_success_total[5m]))

Three rules make these correct:

  1. Aggregate before histogram_quantile, and keep le. Summing bucket rates across replicas and then taking the quantile is correct. Averaging per-replica p95s is not a p95 of anything.
  2. Rate first, then divide. A ratio of two rate()s is the ratio over the window. A ratio of raw counters is the ratio since the process started, and resets with every restart.
  3. Put your objective on a bucket boundary. Percentiles from buckets are interpolated (19.c shows the arithmetic). If your TTFT objective is 800 ms and no bucket ends at 0.8, the share under it is a guess. In v0.32.0 the TTFT buckets include 0.75 and 1.0 but not 0.8, and the queue, prefill and end-to-end histograms share request-latency buckets whose smallest boundary is 0.3 s, so short queue times are coarse (vllm/v1/metrics/buckets.py). --custom-histogram-buckets (new in v0.32.0) moves the boundaries.

Labels and cardinality#

GOOD LABELS (few values, high value)
  model_name, engine            set by vLLM
  pod / instance, zone          added by Prometheus from the scrape target
  model_version                 "v15-fp8-tp8-vllm0.32.0": the full serving configuration,
                                added as a target label so regressions line up with deploys
  finished_reason, reason       set by vLLM, a handful of values each

BAD LABELS (unbounded)
  request_id, user_id, session, prompt hash, exact token counts

Every label value multiplies the series count, and histograms multiply it again by their bucket count (section 4). Tenant is the borderline case: tens of tenants is fine on a gateway metric, hundreds is not, and the engine does not know tenants anyway. Per-tenant and per-request questions belong in the per-request log (23.h), where cardinality is free.

Latency by prompt length. TTFT grows with prompt length (12.c), so an unbucketed TTFT p95 moves whenever the prompt mix moves. vLLM’s latency histograms carry no prompt-length label. Either emit your own TTFT histogram from the gateway with a prompt_bucket label (0-2k, 2k-8k, 8k-32k, 32k+), or watch vllm:request_prompt_tokens next to TTFT so a shift in the mix is visible.

Three dashboards#

Dashboard 1: service health, the one on the wall.

┌──────────────────────┬──────────────────────┬──────────────────────┐
│ TTFT p50 / p95 / p99 │ ITL p50 / p95 / p99  │ Errors and aborts    │
│ + share under SLO    │ + share under SLO    │ by finished_reason   │
├──────────────────────┼──────────────────────┼──────────────────────┤
│ Requests / s         │ Output tokens / s    │ Admission rejections │
├──────────────────────┼──────────────────────┼──────────────────────┤
│ Queue time p95       │ KV cache usage       │ Running vs max seqs  │
│ ↑ overload signal    │ + preemption rate    │ ↑ efficiency signal  │
└──────────────────────┴──────────────────────┴──────────────────────┘

The bottom row is what makes it an LLM dashboard. Put KV cache usage and the preemption rate on one panel: usage near 1.0 with no preemptions is a full, healthy cache; with preemptions it is over-admission (17.c).

Dashboard 2: efficiency and cost.

cost per million output tokens (trended over days)
running batch ÷ max_num_seqs, and tokens per engine step
DCGM DRAM_UTIL_RATIO (decode is memory-bound: this is the real busy, 22.d)
prefix-cache hit rate, and prompt tokens by source
prompt : generation token ratio (the traffic shape)
aborted share, finished_reason="length" share

Dashboard 3: fleet. One row per replica, as heatmaps: KV cache usage, running batch, queue time p95, plus GPU memory, power, SM clock and Xid errors. Imbalance shows as hot rows. One replica at 95% KV and the rest at 20% is a routing problem (20.f), not a capacity problem; a replica whose SM clock sits below the others is throttling (22.c).

vLLM ships starting points: Prometheus and Grafana configurations and dashboards in examples/observability/ (19.c). Use them, then add the efficiency panels they lack.

Alerts: symptoms page, causes ticket#

23.h sets the paging policy (burn-rate alerts on the SLO, what never to page on). For performance work the useful additions are the cause alerts and the efficiency alerts, which go to a ticket queue, not a pager:

YAML
groups:
- name: llm-performance
  rules:
  - record: model:ttft_under_1s:ratio_rate5m
    expr: |
      sum by (model_name) (rate(vllm:time_to_first_token_seconds_bucket{le="1.0"}[5m]))
      / sum by (model_name) (rate(vllm:time_to_first_token_seconds_count[5m]))

  # Cause: overload is building (warn before the SLO breaks)
  - alert: QueueTimeHigh
    expr: |
      histogram_quantile(0.95,
        sum by (le, model_name) (rate(vllm:request_queue_time_seconds_bucket[5m]))) > 2
    for: 5m
    labels: {severity: warn}

  # Cause: the cache is thrashing
  - alert: PreemptionThrashing
    expr: |
      sum by (model_name) (rate(vllm:num_preemptions_total[5m]))
      / sum by (model_name) (rate(vllm:request_success_total[5m])) > 0.05
    for: 10m
    labels: {severity: warn}

  # Cause: requests refused at the door (v0.32.0 queue limits)
  - alert: AdmissionRejections
    expr: sum by (model_name, reason) (rate(vllm:admission_rejections_total[5m])) > 0
    for: 10m
    labels: {severity: warn}

  # Efficiency: paying for idle slots
  - alert: LowRunningBatch
    expr: |
      avg by (model_name) (avg_over_time(vllm:num_requests_running[30m]))
      / on(model_name) group_left() model:max_num_seqs < 0.25
    for: 1h
    labels: {severity: ticket}
    annotations:
      summary: "Running batch is {{ $value | humanizePercentage }} of max_num_seqs: consolidate replicas or check routing"

  # Efficiency: clients giving up
  - alert: HighAbortShare
    expr: |
      sum by (model_name) (rate(vllm:request_success_total{finished_reason="abort"}[15m]))
      / sum by (model_name) (rate(vllm:request_success_total[15m])) > 0.10
    for: 30m
    labels: {severity: ticket}

  # Health: the GPU is not running at full clock
  - alert: GPUClockLow
    expr: |
      DCGM_FI_DEV_SM_CLOCK_HERTZ < 0.85 * on(Hostname, gpu) group_left() gpu:max_sm_clock_hertz
      and DCGM_FI_PROF_GR_ENGINE_UTIL_RATIO > 0.5
    for: 15m
    labels: {severity: warn}

model:max_num_seqs and gpu:max_sm_clock_hertz are series you define yourself (a recording rule or a static exporter), because the engine does not publish its scheduler limits and dcgm-exporter does not publish the clock limit in its default set. The last alert only fires while the GPU is busy, since an idle GPU drops its clock on purpose.

LowRunningBatch is the important one. Most teams alert on being slow; alerting on being idle is what catches “sixteen replicas, each one-tenth full” (22.d).

Cost per token as a metric#

PromQL
# Dollars per million output tokens, per model.
# GPUs come from kube-state-metrics; price per GPU-hour is a series you define.
(
  sum by (model_name) (kube_pod_container_resource_requests{resource="nvidia_com_gpu"}
                       * on(pod) group_left(model_name) pod:model_name)
  * scalar(gpu:price_dollars_per_hour) / 3600
)
/ sum by (model_name) (rate(vllm:generation_tokens_total[1h]))
* 1e6

The joins depend on how your cluster labels pods, so treat this as a shape, not a copy-paste query. What matters: GPUs × price on top, output tokens per second underneath, averaged over an hour so a quiet minute does not spike it. Trend it over days. It is the number that links performance work to money, and the full cost model (prompt tokens, idle capacity, reserved versus on-demand prices) is 23.c.

Traces and logs#

Metrics say what is wrong across the fleet; they cannot say which tenant or which request. Two things complete the picture, and 23.h teaches both:

  • A structured record per request (prompt and output tokens, cached tokens, queue and prefill time, finish reason, model version). The prompt-length distribution for capacity planning (23.b) and the realistic benchmark of 22.g both come from it, not from metrics.
  • Traces, sampled at the tail. vLLM exports a span per request with --otlp-traces-endpoint.

6. Under the hood: what a scrape is#

  • /metrics is a text page. Each line is name{labels} value. Prometheus fetches it every scrape interval (typically 15–30 s), attaches target labels (pod, instance) and stores one sample per series. Nothing is pushed; a dead server simply stops appearing, which is why up == 0 is itself an alert.
  • Counters are totals since the process started. rate() takes the increase between samples in the window and divides by time; it detects a counter reset (a restart) and compensates. This is why you rate() first and aggregate after.
  • Histograms are cumulative counters. The le="0.5" bucket counts every observation up to 0.5 s, including those in smaller buckets. histogram_quantile finds the bucket containing the rank and interpolates linearly inside it; 19.c’s quantiles.go does it by hand.
  • vLLM computes metrics in the API server from facts the engine core attaches to its outputs (19.c). With several API server processes it uses Prometheus’s multiprocess mode, and /metrics aggregates across them.
  • dcgm-exporter samples DCGM on its own interval and publishes one series per GPU (per MIG instance where relevant, 22.d), labelled with gpu, UUID, Hostname and, on Kubernetes, the pod using the GPU.

7. Performance implications#

  • Scrape interval hides bursts. A 30 s scrape and a [5m] rate average away a 5 s spike in queue time. For incident work keep one fast panel (5 s scrape, [1m] rate) on the key gauges, or read the engine’s periodic log line (19.c).
  • Gauges are point samples. vllm:num_requests_running scraped every 30 s is 2 samples a minute of a value that changes every step. avg_over_time over 30 minutes is fine for an efficiency alert; it is not a trace of the batch.
  • Collection is cheap, not free. vLLM’s per-request stats run in the API server’s output loop. --disable-log-stats turns off that collection and every metric with it (19.c); it is not a free speed-up.
  • Cardinality costs the monitoring system, not the server. Prometheus memory grows with active series. Per-engine labels across a large data-parallel deployment, multiplied by LoRA adapters, add up quickly.

8. Production implications#

  • Deploy dcgm-exporter alongside the engine metrics, usually as a Kubernetes DaemonSet, and pin its version: 4.9.0 renamed fields (22.d).
  • Re-check every dashboard after an engine upgrade. Metric names change: vllm:gpu_cache_usage_perc became vllm:kv_cache_usage_perc; v0.32.0 added admission_rejections. A renamed metric makes a panel go blank and an alert stop firing silently. An alert on absent() of a key series catches it.
  • Add a model_version target label with the whole serving configuration (weights, quantisation, parallelism, engine version) so a regression lines up with the deploy that caused it.
  • Keep dashboards few and opinionated. Three dashboards that on-call understands beat thirty that nobody opens.
  • Autoscale on queue signals, not GPU utilisation (19.e, 23.d).

9. Common mistakes#

  1. Only latency panels. Without KV usage, queue time and running batch you see the outage, not the cause.
  2. Averaging per-replica percentiles. Sum the bucket rates, then take the quantile.
  3. Writing vllm:num_preemptions in PromQL. The published counter is vllm:num_preemptions_total; the query returns nothing and the alert never fires.
  4. Reading prefix-cache counters as requests. They count tokens.
  5. Unbucketed TTFT by prompt length, then chasing a “regression” that is a change in the prompt mix.
  6. User or request IDs as labels. Millions of series; put them in logs.
  7. Alerting on GPU utilisation (22.d) or on queue length instead of queue time.
  8. No efficiency alerts, so a fleet running at 20% of its capacity never looks wrong.

10. Hands-on exercise#

  1. Run dashboard.go. Change the bucket count to 40 and the tenants to 30. Which choice costs more series? What is the smallest TTFT bucket boundary set that makes your SLO exact?
  2. Scrape a server. Start vLLM, run curl -s localhost:8000/metrics | grep -E '^vllm:' | cut -d'{' -f1 | sort -u, and find each metric of section 5. Which counters end in _total?
  3. Build Dashboard 1 in Grafana with the PromQL above. Run vllm bench serve (19.d) with rising --request-rate and note the order in which panels move: queue time, KV usage, preemptions, TTFT.
  4. Trigger each alert. Overload for QueueTimeHigh; a small --gpu-memory-utilization and long outputs for PreemptionThrashing; --max-num-queued-reqs 8 for AdmissionRejections; one client at low rate for LowRunningBatch.
  5. Find the imbalance. Route all traffic to one of two replicas and confirm the fleet heatmap shows it within a minute.
  6. Cost per token. Compute it for one hour of a benchmark and compare with the hand calculation in 23.c.

11. Interview questions#

  1. Which metrics would you put on an LLM serving dashboard that a generic web dashboard lacks, and what does each tell you?
  2. TTFT p95 doubled. Which two panels tell you whether to add capacity or look at prefill?
  3. Why is averaging per-replica p95s wrong, and what is the correct PromQL?
  4. What is cardinality, and why must user IDs never be metric labels?
  5. KV cache usage is 0.97. Is that good or bad? What else do you need to know?
  6. How would you compute cost per million output tokens from Prometheus, and why use a one-hour window?
  7. Why alert on low running batch, and why is it a ticket rather than a page?

12. Further reading#

Checked on 13 November 2026 against vLLM v0.32.0 and dcgm-exporter 4.9.0.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in