mstar.observability.metrics#
Prometheus metrics for the API server: --enable-metrics and GET /metrics.
Requests are counted where they leave APIServer,
which /generate, /generate/ws, the OpenAI routes, the Rust-frontend
bridge and the Dynamo bridge all go through. Requests the HTTP frontend
refuses before that (a missing API key, a body over the limit, a bad form)
are counted by route and status in mstar_http_refusals_total. Each family
carries the deployment’s model_name; every other label takes values from
a fixed set.
Only the API server process imports prometheus_client and renders
/metrics. Other processes (data worker, conductor, workers) send plain
numbers on messages they already send the API server, plus the conductor’s
periodic status message, and the API server records them here; no
multiprocess directory, which would only aggregate one host. Families whose
values come from another process are defined in catalog.
prometheus_client is optional (pip install 'mstar[metrics]') and only
needed when metrics are on.
Module Attributes
the request failed (engine, preprocessing, result delivery, conductor gone). |
Functions
The HTTP request being served reached |
|
|
One label value per set of input or output modalities, e.g. |
|
The route path the request matched ( |
Classes
|
Counts |
|
The API server's registry and its request metrics. |
- mstar.observability.metrics.OUTCOMES = ('success', 'error', 'abort', 'timeout')#
the request failed (engine, preprocessing, result delivery, conductor gone).
abort: the client went away, or its finished result was dropped unread.timeout: the per-request--timeoutexpired.- Type:
success- Type:
the result went to the HTTP layer.
error
- class mstar.observability.metrics.RefusalMiddleware(app, metrics, routes)[source]#
Bases:
objectCounts
mstar_http_refusals_totalfor the Python frontend: every HTTP response with a 4xx status for a request that never reachedAPIServer.submit_request(mark_submitted()). A request that was submitted and then failed is counted bymstar_requests_totalinstead.Sits outside the API key and body limit middlewares (their 401 and 413 are sent before routing) and inside CORS (a preflight is not a request). WebSocket handshakes are not counted. With metrics off it only checks
metrics()for None.- Parameters:
metrics (Callable[[], ServingMetrics | None])
routes (Callable[[], Iterable])
- class mstar.observability.metrics.ServingMetrics(model_name, in_flight, data_worker_queue_depth, local_status=None)[source]#
Bases:
objectThe API server’s registry and its request metrics.
- Parameters:
model_name (str)
in_flight (Callable[[], int])
data_worker_queue_depth (Callable[[], int])
local_status (Callable[[], list[MetricSnapshot]] | None)
- conductor_status(status)[source]#
Export the conductor’s latest status message.
- Parameters:
status (ConductorStatus)
- Return type:
None
- record(req, outcome)[source]#
Count one request that left the API server’s table.
- Parameters:
req (PendingRequest)
outcome (str)
- Return type:
None
- record_chunk(modality, data, metadata)[source]#
Count one result chunk that reached the API server (not an error chunk).
- record_preprocess(profile)[source]#
Record the data worker’s numbers for one request it took off its queue: its time if preprocessing finished, else a failure, and the size of each input file either way.
- Parameters:
profile (DataWorkerProfile)
- Return type:
None
- mstar.observability.metrics.mark_submitted()[source]#
The HTTP request being served reached
APIServer: it is counted inmstar_requests_totalwhen it ends, so it is never a refusal.- Return type:
None
- mstar.observability.metrics.modalities_label(modalities)[source]#
One label value per set of input or output modalities, e.g.
audio,text.
- mstar.observability.metrics.route_template(scope, routes)[source]#
The route path the request matched (
/v1/chat/completions), never the raw URL;unmatchedwhen no route matches.routesare the app’s routes, searched for a request refused before routing (the API key, a declared body size) the way the router matches: a full match before a method-only one.