stormlog.infer.vllm_metrics
Prometheus text parsing and the vLLM metric catalog.
The parser reads the text exposition that prometheus_client writes for
vLLM: # HELP and # TYPE lines name a family, a counter family is
named *_total with a separate *_created gauge, and a histogram family
exposes _bucket{le=...}, _sum and _count samples. Nothing here
imports vLLM, and nothing here turns a scrape into a per-request number: a
scrape describes every request the engine served, from every client.
The catalog names what vLLM 0.30.0 exposes and what each series means. A series the catalog does not name is kept under its native name, never dropped; a name vLLM has retired is recognised and mapped to its successor.
Functions
|
The numeric upper bound of a bucket; |
|
Fold parsed families into the compact per-scrape form. |
|
The |
|
The inverse of |
|
Compare a scrape with the catalog without discarding anything. |
|
A sample value as strict JSON: NaN and infinities become strings. |
|
The catalog group of a series; optional prefixes name their subsystem. |
|
Parse a text scrape into families keyed by their |
|
The exporting process's start time, or None when a scrape has no single one. |
|
Return the current catalog name and the retired alias it replaced, if any. |
Classes
|
What one vLLM series means and how Stormlog refers to it. |
|
One scrape with every series kept, label sets shared across series. |
|
What one scrape exposes, measured against the catalog. |
|
Cumulative bucket counts under their native |
|
A |
|
One exposed series: its full sample name, sorted labels and value. |
Exceptions
A line over |
- exception stormlog.infer.vllm_metrics.ScrapeTooLarge[source]
Bases:
ValueErrorA line over
MAX_LINE_CHARS, or more series or families than allowed.
- class stormlog.infer.vllm_metrics.Sample(name, labels, value)[source]
Bases:
objectOne exposed series: its full sample name, sorted labels and value.
- Parameters:
name (str)
labels (tuple[tuple[str, str], ...])
value (float)
- name: str
- labels: tuple[tuple[str, str], ...]
- value: float
- class stormlog.infer.vllm_metrics.MetricFamily(name, kind, help, samples=())[source]
Bases:
objectA
# TYPEfamily and the samples that belong to it.- Parameters:
name (str)
kind (str)
help (str)
samples (tuple[Sample, ...])
- name: str
- kind: str
- help: str
- stormlog.infer.vllm_metrics.parse_prometheus_text(text, *, max_series=None)[source]
Parse a text scrape into families keyed by their
# TYPEname.A sample without a preceding
# TYPEline belongs to anuntypedfamily of its own name. A line that is neither a comment nor a sample raisesValueErrornaming the line, so a truncated or HTML response never passes as an empty scrape.What parsing holds is bounded whatever the text: lines are read one at a time, a line over
MAX_LINE_CHARSraisesScrapeTooLargebefore any regex sees it, and so does a sample or family pastmax_series.- Parameters:
text (str)
max_series (int | None)
- Return type:
dict[str, MetricFamily]
- class stormlog.infer.vllm_metrics.HistogramValue(buckets, sum, count)[source]
Bases:
objectCumulative bucket counts under their native
leboundaries.sumorcountis None when the exposition lacked that sample: it is kept missing, never invented as zero, so nothing differences it.- Parameters:
buckets (tuple[tuple[str, float], ...])
sum (float | None)
count (float | None)
- buckets: tuple[tuple[str, float], ...]
- sum: float | None
- count: float | None
- property boundaries: tuple[float, ...]
- stormlog.infer.vllm_metrics.encode_number(value)[source]
A sample value as strict JSON: NaN and infinities become strings.
- Parameters:
value (float)
- Return type:
float | str
- stormlog.infer.vllm_metrics.decode_number(value)[source]
The inverse of
encode_number(); other strings are an error.- Parameters:
value (Any)
- Return type:
float
- stormlog.infer.vllm_metrics.bucket_boundary(le)[source]
The numeric upper bound of a bucket;
+Infis infinity.- Parameters:
le (str)
- Return type:
float
- class stormlog.infer.vllm_metrics.CompactScrape(families, label_sets, values, helps=<factory>)[source]
Bases:
objectOne scrape with every series kept, label sets shared across series.
valuesmaps a family name to{label set id: value}; a value is a float for gauges, counters and untyped series, and aHistogramValuefor histograms. Summaries keep their quantiles as a histogram-like value whose bucket boundaries are quantiles.- Parameters:
families (dict[str, str])
label_sets (dict[str, dict[str, str]])
values (dict[str, dict[str, float | HistogramValue]])
helps (dict[str, str])
- families: dict[str, str]
- label_sets: dict[str, dict[str, str]]
- values: dict[str, dict[str, float | HistogramValue]]
- helps: dict[str, str]
- series(name)[source]
Values of one family by label set id; empty when absent.
- Parameters:
name (str)
- Return type:
dict[str, float | HistogramValue]
- stormlog.infer.vllm_metrics.compact_scrape(families)[source]
Fold parsed families into the compact per-scrape form.
- Parameters:
families (dict[str, MetricFamily])
- Return type:
- class stormlog.infer.vllm_metrics.CatalogEntry(name, kind, field, group, unit, meaning, labels=(), requires=None, provenance='observed')[source]
Bases:
objectWhat one vLLM series means and how Stormlog refers to it.
- Parameters:
name (str)
kind (str)
field (str)
group (str)
unit (str | None)
meaning (str)
labels (tuple[str, ...])
requires (str | None)
provenance (str)
- name: str
- kind: str
- field: str
- group: str
- unit: str | None
- meaning: str
- labels: tuple[str, ...] = ()
- requires: str | None = None
- provenance: str = 'observed'
- stormlog.infer.vllm_metrics.created_family_for(name, kind='counter')[source]
The
*_createdgauge that marks when a counter or histogram was made.prometheus_client names a counter’s stamp without the
_totalsuffix (vllm:prompt_tokens_created) but a histogram’s with its full name, sovllm:iteration_tokens_total, a histogram despite the suffix, is stamped asvllm:iteration_tokens_total_created.- Parameters:
name (str)
kind (str)
- Return type:
str | None
- stormlog.infer.vllm_metrics.resolve_name(name)[source]
Return the current catalog name and the retired alias it replaced, if any.
- Parameters:
name (str)
- Return type:
tuple[str, str | None]
- class stormlog.infer.vllm_metrics.Discovery(present, absent, optional_absent, deprecated_present, removed_present, unknown, engines, model_names, process_start_ns, optional_present=())[source]
Bases:
objectWhat one scrape exposes, measured against the catalog.
- Parameters:
present (tuple[str, ...])
absent (tuple[str, ...])
optional_absent (tuple[str, ...])
deprecated_present (tuple[str, ...])
removed_present (tuple[str, ...])
unknown (tuple[str, ...])
engines (tuple[str, ...])
model_names (tuple[str, ...])
process_start_ns (int | None)
optional_present (tuple[str, ...])
- present: tuple[str, ...]
- absent: tuple[str, ...]
- optional_absent: tuple[str, ...]
- deprecated_present: tuple[str, ...]
- removed_present: tuple[str, ...]
- unknown: tuple[str, ...]
- engines: tuple[str, ...]
- model_names: tuple[str, ...]
- process_start_ns: int | None
- optional_present: tuple[str, ...] = ()
- stormlog.infer.vllm_metrics.discover(scrape)[source]
Compare a scrape with the catalog without discarding anything.
- Parameters:
scrape (CompactScrape)
- Return type:
- stormlog.infer.vllm_metrics.process_start_ns(scrape)[source]
The exporting process’s start time, or None when a scrape has no single one.
- Parameters:
scrape (CompactScrape)
- Return type:
int | None