Skip to content

InsightsAI Infrastructure

Monitoring and autoscaling vLLM on Kubernetes

Which vLLM metrics tell you a replica is saturated, how to alert on them, and how to scale on queue depth with KEDA instead of CPU, GPU utilisation or request rate.

Published October 29, 20268 min read

An LLM inference pod can look healthy in every standard dashboard while users wait. CPU is low because the work happens on the GPU. GPU utilisation is high, but it is high at ten requests and at a hundred. The pod answers its health check, and requests still sit in a queue for a minute.

vLLM exports Prometheus metrics that describe the problem directly: how many requests are waiting, how full the KV cache is, and how long the first token takes. This article covers the metrics worth keeping, the alerts to build from them and how to autoscale on queue depth. It uses vLLM as the example engine, and the same approach applies to any server that exposes a queue.

Where the metrics come from

The vLLM OpenAI-compatible server serves Prometheus metrics at /metrics on the same port as the API. Metric names use the vllm: prefix, which is legal in Prometheus but easy to mistype in a query, and series carry a model_name label. Scrape them with a PodMonitor or ServiceMonitor like any other workload:

podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: vllm
spec:
  selector:
    matchLabels:
      app: vllm
  podMetricsEndpoints:
    - port: http
      path: /metrics
      interval: 15s

Open /metrics once by hand before you write any query. The metric set changes between releases, and the exact exposed names, including suffixes on counters, are the ones in your output rather than the ones in an article.

The metrics that matter

The full list is long. These are the ones that answer operational questions, with names from the vLLM metrics documentation:

QuestionMetricType
Are requests waiting for capacity?vllm:num_requests_waitingGauge
How many are being served?vllm:num_requests_runningGauge
Is the KV cache full?vllm:kv_cache_usage_perc (1 means 100%)Gauge
Is the engine evicting work?vllm:num_preemptionsCounter
How long until the user sees output?vllm:time_to_first_token_secondsHistogram
How fast does the stream flow?vllm:inter_token_latency_secondsHistogram
Where does the time go?vllm:request_queue_time_seconds, vllm:request_prefill_time_seconds, vllm:request_decode_time_secondsHistograms
Whole requestvllm:e2e_request_latency_secondsHistogram
Is prefix caching helping?vllm:prefix_cache_hits, vllm:prefix_cache_queriesCounters

Each one points at a different cause:

  • Waiting requests above zero for a sustained period means demand exceeds what the replica can run at once. This is the earliest signal of saturation and the best autoscaling input.
  • KV cache usage close to 1 explains why. The cache holds the attention state for every running sequence, so long prompts and long outputs fill it. When it is full, new requests wait or running ones are preempted, which is the arithmetic from sizing GPUs for LLM inference.
  • A rising preemption rate means work is being evicted and redone. Latency climbs even though the queue may look short.
  • Time to first token is mostly queue time plus prefill. The per-phase histograms tell you which one grew. Long prompts push prefill up; saturation pushes queue time up.
  • Inter-token latency reflects decode speed and batch size. If it degrades while the queue is empty, look at the batch, the hardware or noisy neighbours on the node, not at replica count.

Prefix cache hits are an efficiency number rather than a health one. A hit ratio that drops after a prompt template change is a useful explanation for a latency regression.

Alerts that point at a cause

Latency alerts alone do not say what to do. Pair a symptom with a cause so the person on call knows where to look. Rules like these use the metrics above; tune the thresholds from your own load tests:

vllm-alerts.yaml
groups:
  - name: vllm
    rules:
      - alert: VllmQueueBuilding
        expr: sum by (model_name) (vllm:num_requests_waiting) > 10
        for: 5m
        labels:
          severity: ticket
        annotations:
          summary: "Requests are queueing for {{ $labels.model_name }}"
 
      - alert: VllmTimeToFirstTokenSlow
        expr: |
          histogram_quantile(0.95,
            sum by (le, model_name) (rate(vllm:time_to_first_token_seconds_bucket[5m]))
          ) > 2
        for: 10m
        labels:
          severity: page
        annotations:
          summary: "p95 time to first token above 2s for {{ $labels.model_name }}"
 
      - alert: VllmKvCacheNearlyFull
        expr: max by (pod) (vllm:kv_cache_usage_perc) > 0.95
        for: 10m
        labels:
          severity: ticket
        annotations:
          summary: "KV cache above 95% on {{ $labels.pod }}"

Two points about these rules:

  • Page on the user-facing symptom, ticket on the cause. Time to first token is what users feel. A full cache or a queue is where you start digging. Treat the first as an SLO and use burn-rate alerting once you have enough traffic for it to be meaningful.
  • Histograms are cardinality-heavy. Each histogram produces a series per bucket, per label combination, per pod. Keep the label set small, and drop the per-request token histograms and any other histograms you never query if Prometheus storage becomes a problem. vLLM also accepts --custom-histogram-buckets to change the bucket boundaries of the families you list.

Why CPU-based scaling fails

The default HorizontalPodAutoscaler scales on CPU or memory. An inference server breaks that model in three ways:

  • CPU use stays low while the GPU is saturated, so the HPA never fires.
  • GPU utilisation says the device is busy, not that demand exceeds capacity. A GPU at 95% with an empty queue is working as intended.
  • Request rate is a poor proxy because requests differ by orders of magnitude. One request with a 30,000-token prompt costs more than fifty short chat turns.

Queue depth measures what you care about: work that has arrived and cannot start. It rises when you are under-provisioned and falls to zero when you are not, regardless of request shape. That makes vllm:num_requests_waiting the signal the vLLM production-stack documentation uses in its KEDA autoscaling tutorial.

Scaling on queue depth with KEDA

KEDA queries Prometheus directly and creates a standard HPA behind the scenes, so no Prometheus adapter or custom metrics API is needed. The Amazon EKS guide to autoscaling AI inference with HPA and KEDA uses two triggers: queue depth as the primary signal and p95 end-to-end latency as a guardrail. A version of that configuration:

scaledobject.yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: vllm
spec:
  scaleTargetRef:
    name: vllm
  minReplicaCount: 1
  maxReplicaCount: 5
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleUp:
          stabilizationWindowSeconds: 30
          policies:
            - type: Pods
              value: 2
              periodSeconds: 60
        scaleDown:
          stabilizationWindowSeconds: 300
          policies:
            - type: Pods
              value: 1
              periodSeconds: 120
  triggers:
    - type: prometheus
      metricType: AverageValue
      metadata:
        serverAddress: http://prometheus.monitoring.svc:9090
        query: sum(vllm:num_requests_waiting) or vector(0)
        threshold: "25"
        activationThreshold: "1"

The pieces that matter:

  • metricType: AverageValue divides the query result by the replica count, so threshold: "25" means about 25 waiting requests per replica. The query sums across pods; the threshold is per pod.
  • or vector(0) returns zero instead of an empty result when nothing is waiting, so the trigger does not turn inactive or error on an idle system.
  • activationThreshold is separate from the scaling threshold. It decides whether KEDA treats the scaler as active at all, which matters mainly if you allow scale to zero.
  • Fast up, slow down. A short scale-up window reacts while users are already waiting. A long scale-down window avoids removing a GPU you will need again in two minutes, because a new replica takes as long to start as the slowest step in the cold-start path.

The threshold of 25 is an example from that guide, not a recommendation. Find yours by load testing one replica with your real prompt and output lengths, and look for the queue depth at which time to first token crosses your target. The production-stack tutorial uses a threshold of 5 with a small replica range, which shows how far the right value depends on the model and hardware.

What goes wrong

  • Scaling is slower than the spike. A new replica must get a GPU, pull the image, load weights and capture graphs before it takes traffic. Queue-based scaling reacts to demand that is already waiting, and the new capacity arrives minutes later. Keep a floor of warm replicas sized for your normal peak, and use scheduled scaling for known daily peaks. Autoscaling covers the unexpected surplus.
  • Nodes are the real limit. The HPA can ask for replicas that stay Pending because no GPU node is free. Scaling pods needs a node autoscaler behind it, as described in Kubernetes autoscaling from pods to nodes, and GPU quota that allows the maximum you configured.
  • Load balancing hides saturation. A plain Service round-robins by connection, not by queue. One replica can have a deep queue while another is idle. Watch the per-pod values of vllm:num_requests_waiting, not just the sum, and consider a gateway that routes by load.
  • Scaling on the average of a bad signal. Summing the queue is stable. Averaging p95 latency across pods is not meaningful, so compute quantiles from summed bucket rates, as in the alert above.
  • Metrics disappear when a pod does. A pod killed mid-spike takes its last data points with it. Short scrape intervals and a gateway that records its own request latency give you a second view that survives replica churn.
  • Flapping. Without a stabilization window, the HPA adds and removes replicas as the queue oscillates, and every removal throws away a loaded model. Lengthen the scale-down window before you tune anything else.

Where to start

  1. Scrape /metrics, read the real output of the version you run and list the metrics your dashboards use.
  2. Build one dashboard with waiting and running requests, KV cache usage, preemptions and p95 time to first token, split by pod.
  3. Load test one replica with realistic prompts and record the queue depth at which latency breaches your target.
  4. Add the alerts: a symptom alert on time to first token and cause alerts on queue and cache.
  5. Add a KEDA ScaledObject on queue depth with a slow scale-down, a floor of warm replicas and a ceiling your GPU quota can serve.
  6. Re-run the load test after every vLLM upgrade, and check that the metrics your alerts depend on still exist.