1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Inference-runtime serving load as a ``source_load`` signal (vLLM / SGLang).
The MX client runs inside the inference worker's pod, so it can scrape the
worker's own Prometheus ``/metrics`` and turn a serving-load proxy into a
``[0, 1]`` ``source_load``. This complements the physical NIC-utilization
provider (`nic_metrics.py`): the runtime signal is *predictive* -- a full KV
cache or a deep prefill queue foretells RDMA the NIC counter has not seen yet --
and it works on fabrics the sysfs counters cannot read.
It reads whichever known load metric is present, so the same provider covers
vLLM and SGLang without configuration beyond the endpoint URL
(``MX_P2P_RUNTIME_METRICS_URL``). Everything is best-effort: an unreachable
endpoint or an unrecognized exposition yields ``0.0``, so the blend falls back
to the NIC signal (and ultimately to ``rendezvous_hash``).
"""
=
# Metrics already expressed as a [0, 1] utilization ratio, in priority order.
# vLLM: fraction of KV-cache blocks in use (renamed kv_cache_usage_perc in
# v0.17; gpu_cache_usage_perc on older builds). SGLang: token/KV usage fraction.
# dynamo_component_gpu_cache_usage_percent is Dynamo's runtime-agnostic re-export
# of the same GPU KV-cache usage (0.0-1.0); kept last so engine-specific gauges
# still win on vLLM/SGLang and this only resolves a signal where they are absent
# (e.g. TRT-LLM behind a Dynamo runtime).
=
"""Return the max value across series of Prometheus gauge ``name`` (or None).
Matches ``name`` and ``name{labels...}`` lines; skips ``# HELP``/``# TYPE``.
Taking the max over label series is the conservative choice (busiest shard).
"""
=
: = None
continue
=
=
continue
=
return
"""Provides ``source_load`` in ``[0, 1]`` from a runtime's /metrics endpoint."""
=
=
= or
"""KV-cache utilization in ``[0, 1]``, or ``None`` when nothing was read.
An unreachable endpoint or an engine that exports none of the known
gauges is "no reading", not "idle"; publishing 0.0 for it would make the
source look free to every puller.
"""
=
return None
=
return
return None
# noqa: S310
return
# pragma: no cover - network best-effort
return None