> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m-star.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitor a deployment

> Enable Prometheus metrics, find the source of latency and read the complete metric-family reference.

Enable metrics to see whether a slowdown begins before admission, inside the workers or during delivery. The endpoint exposes Prometheus text at `/metrics`, including on a server that requires a bearer key for inference.

## Enable metrics

Install the `metrics` extra alongside the model’s dependencies and pass `--enable-metrics`. For a [Kokoro](https://docs.m-star.org/models/kokoro.md#serve) deployment:

```bash theme={null}
uv pip install --torch-backend=auto 'mstar-ai[kokoro,metrics]'
mstar serve kokoro --enable-metrics
```

After `/health` reports ready, send an inference request and run `curl -fsS http://localhost:8000/metrics`. A disabled endpoint returns 404. Labeled series appear when first used.

## Choose a measurement

| Question | Look at |
| - | - |
| Did the server accept the request? | [HTTP refusals](#http-refusals) for pre-submission failures and [request outcomes](#requests) for submitted requests. |
| Where is latency accumulating? | [Preprocess, admission, engine and delivery](#request-stages). For speech, compare first-audio latency with [output volume](#output). |
| Is a worker at capacity? | [Conductor queue](#conductor), [pending steps, KV pages and preemptions](#engine-workers). |
| Are transfers expensive? | [Consumer-side bytes and time](#tensor-transport), broken down by edge and transport. |

## Prometheus and Grafana

`examples/observability/` runs Prometheus and Grafana in Docker Compose against an M\* server on the host. From the repository root:

```bash theme={null}
mstar serve kokoro --enable-metrics          # on the host, port 8000
docker compose -f examples/observability/docker-compose.yml up -d
```

Prometheus (`localhost:9090`) scrapes `/metrics` every 5 seconds. Grafana (`localhost:3000`) has Prometheus as its default data source and loads any dashboard JSON placed in `examples/observability/grafana/dashboards/`. The example's README covers how the containers reach the host on Linux, a server on another port, and the optional anonymous viewer. Stop the containers with `docker compose -f examples/observability/docker-compose.yml down`.

The `M* serving` dashboard there (`mstar.json`) has a panel for every family on this page, in one row per component: requests, request stages and output, data worker, conductor, engine workers, tensor transport and HTTP refusals. Its `model` variable picks the `model_name` values to show.

To scrape from an existing Prometheus, add a job for the server's address:

```yaml theme={null}
scrape_configs:
  - job_name: mstar
    metrics_path: /metrics
    scrape_interval: 5s
    static_configs:
      - targets: ["localhost:8000"]
```

The conductor and workers report once a second, so a scrape interval under a second only repeats values. Keep the scrape timeout above two seconds: `mstar-server` waits that long for the bridge before answering `503`.

## Example queries

These aggregate every matching series; add a `model_name` selector to look at one model. A KV cache that two nodes share shows under each node, so read [Engine workers](https://docs.m-star.org/metrics.md#engine-workers) before summing KV gauges over `component`.

```text theme={null}
# Requests per second by outcome
sum by (outcome) (rate(mstar_requests_total[1m]))

# Share of requests that did not succeed
sum(rate(mstar_requests_total{outcome!="success"}[5m]))
  / sum(rate(mstar_requests_total[5m]))

# p95 end-to-end latency and time to first output
histogram_quantile(0.95, sum by (le) (rate(mstar_e2e_request_latency_seconds_bucket[5m])))
histogram_quantile(0.95, sum by (le) (rate(mstar_time_to_first_output_seconds_bucket[5m])))

# KV cache use per node and cache
mstar_kv_pages_used / mstar_kv_pages_total

# The conductor stopped reporting (alert)
mstar_conductor_status_age_seconds > 10
```

## Check freshness

The API server renders a single registry. Its own values are current at scrape time. The conductor reports every second. Worker updates pass through the conductor and can lag by roughly two seconds in a healthy deployment. If `mstar_conductor_status_age_seconds` rises, those values may be older. A Rust frontend that cannot obtain the registry from its backend can return 503.

## Conventions

* Names use Prometheus base units (`_seconds`, `_bytes`), and counters end in `_total`. Read counters and histograms with `rate()` or `increase()`.
* Every family has a `model_name` label: the config's `model` key (the registry name, e.g. `kokoro` or `qwen3_omni`).
* Label values come from fixed sets or from the model and its config, never from requests, so the number of series is bounded:
  * `outcome`: `success`, `error`, `abort`, `timeout`.
  * `output_modalities` and `input_modalities`: the request's modalities, sorted and comma-joined (`audio,text`), from `text`, `image`, `audio`, `video`, `video_frame`, `action`, `scalar`, `tensor`. In practice a model has a few combinations.
  * `modality`: one of those modality names.
  * `state`: `waiting`, `running`, `draining`.
  * `component`: a graph node name from the config's `node_groups`.
  * `graph_walk`: a graph walk name of the model.
  * `resource`: the key of a paged KV cache in the model.
  * `src` and `dst`: a graph node name, or `api_server`.
  * `transport`: `SHM`, `TCP`, `RDMA`.
  * `route`: a route path as declared (`/v1/chat/completions`), or `unmatched`.
  * `status`: an HTTP status code the frontend sent (a `4xx`, or `503`).
  * `term`: `prefix`, the term of the config's `routing_weights` other than `load`.
* A labeled series appears the first time it is used. For a new set of output modalities, `mstar_requests_total` exports all four outcomes at zero from that request on, and the data worker's two families start together, so a later first error shows in `rate()`. `rate()` and `increase()` miss what was counted before the first scrape that saw a series: if a set's first request fails, its error series starts at 1.

## Account for warmup and failures

Request histograms, step counters and transfers begin after warmup. Gauges can reflect resources allocated at worker startup. Read request latency histograms together with success and failure counts, since a successful-request histogram excludes failed calls.

## Requests

`mstar_requests_total{model_name, output_modalities, outcome}` \

Counter. Requests that left the API server. Outcomes are `success`, `error`, `abort` and `timeout`. An unread result discarded after its client disconnects is an abort.

`mstar_requests_in_flight{model_name}` \

Gauge. Requests submitted and still held by the API server at scrape time.

`mstar_e2e_request_latency_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from submission after body read to the result leaving the API server. Excludes client network time.

`mstar_time_to_first_output_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from submission to the first result chunk of any modality.

## Request stages

These successful-request stages use clocks on the same host.

`mstar_request_preprocess_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from submission to handoff to the conductor. Includes time queued at the data worker.

`mstar_request_queue_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from conductor intake to admission for dispatch. Zero when no admission wait occurred.

`mstar_request_engine_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from conductor dispatch to completion on the conductor. Excludes admission wait.

`mstar_request_delivery_seconds{model_name, output_modalities}` \

Histogram. Successful requests, from conductor completion to the result leaving the API server. Includes postprocessing and pickup of the last result.

## Output

`mstar_output_chunks_total{model_name, modality}` \

Counter. Result chunks across outcomes. Error chunks are excluded.

`mstar_output_bytes_total{model_name, modality}` \

Counter. Result payload bytes across outcomes.

`mstar_output_audio_seconds_total{model_name}` \

Counter. PCM16 audio duration using each chunk’s sample rate and channel count. Chunks missing a sample rate are excluded.

`mstar_time_to_first_chunk_seconds{model_name, modality}` \

Histogram. Successful requests, from submission to first chunk for each modality. Select `modality="audio"` for time to first audio.

## Preprocessing

Compare queue depth with active preprocess time to distinguish backlog from slow media decoding.

`mstar_data_worker_preprocess_seconds{model_name, input_modalities}` \

Histogram. Time from dequeue to handoff to the conductor for requests that finish preprocessing. Excludes queue wait.

`mstar_data_worker_preprocess_failures_total{model_name, input_modalities}` \

Counter. Requests whose media loading, preprocessing or input handoff failed.

`mstar_upload_size_bytes{model_name, modality}` \

Histogram. Bytes per media file presented to preprocessing, after decoding inline uploads. Includes files from failed requests.

`mstar_data_worker_queue_depth{model_name}` \

Gauge. Submitted requests still waiting for the data worker. Excludes requests already being processed.

## HTTP refusals

Exported by the API server, counted by whichever frontend serves the deployment.

`mstar_http_refusals_total{model_name, route, status}` \

Counter. HTTP requests the frontend answered with an error without submitting them to the API server: `401` (missing or wrong API key), `413` (body over `MSTAR_MAX_BODY_MB`), `422` (body that fails validation), `400` (a bad form field or request), `409` (a `request_id` in flight), `404` (unknown route, or a model without the endpoint), `405` (wrong method), and `503` when the Rust frontend's `MSTAR_MAX_CONCURRENT_REQUESTS` cap turns a request away. WebSocket handshakes are not counted. Unless `--python-frontend` is set, the values are the totals `mstar-server` sent with the latest `/metrics` request.

## Conductor

`mstar_conductor_requests{model_name, state}` \

Gauge. Requests held by the conductor. `waiting` counts queued requests, `running` counts dispatched requests and `draining` counts finished requests waiting for readers to release outputs. Draining requests still occupy a slot.

`mstar_component_in_flight{model_name, component}` \

Gauge. Running requests with an outstanding graph pass on this node. A decode loop counts once for the pass.

`mstar_routing_predicted_saving_total{model_name, term}` \

Counter. Unweighted routing credit on the chosen replica. For `term="prefix"`, each request adds the predicted cached share of its prompt. This differs from a token-weighted cache hit rate.

`mstar_conductor_status_age_seconds{model_name}` \

Gauge. Time since the latest conductor status message, or since enabling metrics if none has arrived. Read this before relying on worker and conductor gauges.

## Engine workers

Workers report per graph node. Replicas sum across workers. TP, SP and CFG groups report once per instance. A physical cache shared by nodes appears under each node. Inspect individual resources before aggregating. [Admission and preemption](https://docs.m-star.org/serving.md#kv-admission)

`mstar_kv_pages_used{model_name, component, resource}` \

Gauge. Pages held by requests or the prefix cache. Query by `component` and `resource`. A shared cache can appear under more than one node.

`mstar_kv_pages_total{model_name, component, resource}` \

Gauge. Device KV pages available to requests in this cache.

`mstar_kv_pages_cached{model_name, component, resource}` \

Gauge. Pages referenced by the prefix cache, including some also held by active requests. Pages held solely by the cache can be evicted.

`mstar_kv_pages_lent{model_name, component, resource}` \

Gauge. Reserved pages lent by guaranteed requests and currently occupied.

`mstar_rebuild_host_bytes_used{model_name, component}` \

Gauge. Bytes of a worker's rebuild host pool that hold kept prompt ids and host copies, which a request dropped from the KV cache is rebuilt from.

`mstar_rebuild_host_bytes_total{model_name, component}` \

Gauge. Bytes of a worker's rebuild host pool (the serving config's rebuild\_host\_mb).

`mstar_step_seconds{model_name, component, graph_walk}` \

Histogram. Worker time per completed step, from handoff to the GPU thread or the previous completion, whichever is later, through postprocess. Overlapped work counts once.

`mstar_batch_size{model_name, component, graph_walk}` \

Histogram. Engine steps: rows the step's forward ran.

`mstar_prefix_cache_query_tokens_total{model_name, component}` \

Counter. Tokens looked up in the prefix cache, once per eligible request. In a tensor-parallel instance only the lead rank counts.

`mstar_prefix_cache_hit_tokens_total{model_name, component}` \

Counter. Tokens found in the KV prefix cache at lookup time. A recurrent-state snapshot can shorten the usable prefix afterwards.

`mstar_kv_preemptions_total{model_name, component}` \

Counter. Requests selected for host offload or drop when pages are needed.

`mstar_kv_drops_total{model_name, component}` \

Counter. Preempted requests whose KV was discarded for later reconstruction.

`mstar_kv_rebuild_tokens_total{model_name, component}` \

Counter. Tokens of kept history the rebuild rows prefilled, cache hits included.

`mstar_kv_rebuild_cached_pages_total{model_name, component}` \

Counter. Pages a rebuild row found in the prefix cache.

`mstar_kv_preempted_again_total{model_name, component}` \

Counter. Requests preempted a second time. Sustained growth suggests pressure on the KV pool.

`mstar_kv_returns_preempted_total{model_name, component}` \

Counter. Requests with a rebuild log that were preempted again before they sampled another token.

`mstar_kv_take_backs_total{model_name, component}` \

Counter. Preemptions to reclaim lent pages. Also included in `mstar_kv_preemptions_total`.

`mstar_kv_take_back_waits_total{model_name, component}` \

Counter. Times a guaranteed request waited to reclaim lent pages because no borrower could move.

`mstar_component_pending_steps{model_name, component}` \

Gauge. Requests with inputs ready for this node, waiting for room in a batch or for the scheduler to select the node.

For a token-weighted prefix hit rate over five minutes, divide `sum(rate(mstar_prefix_cache_hit_tokens_total[5m]))` by `sum(rate(mstar_prefix_cache_query_tokens_total[5m]))`. Use matching selectors for model and component.

## Tensor transport

The consumer records each edge read. `src` and `dst` are nodes or `api_server`. A tensor already at its destination requires no transfer. Multiple ranks reading the same edge each count their own read.

`mstar_transfer_bytes_total{model_name, src, dst, transport}` \

Counter. Tensor bytes the consumer read from the producer over this edge.

`mstar_transfers_total{model_name, src, dst, transport}` \

Counter. Tensors read over this edge by the consumer.

`mstar_transfer_seconds{model_name, src, dst, transport}` \

Histogram. Consumer-side duration per edge read. The producer’s write or registration is measured separately in request profiles. A GPU consumer may only have enqueued its H2D copy when the timing ends.

## Histogram buckets

Upper bounds, without `+Inf`:

* **E2E** (`mstar_e2e_request_latency_seconds`, `mstar_request_engine_seconds`): 0.05, 0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 5, 7.5, 10, 15, 20, 30, 60, 120, 300, 600, 1200 s.
* **First output** (`mstar_time_to_first_output_seconds`, `mstar_time_to_first_chunk_seconds`): 0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.5, 0.75, 1, 1.5, 2, 3, 5, 7.5, 10, 20, 30, 60, 120, 300, 600 s.
* **Stage** (`mstar_request_preprocess_seconds`, `mstar_request_delivery_seconds`, `mstar_data_worker_preprocess_seconds`): 0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120, 300, 600 s.
* **Queue** (`mstar_request_queue_seconds`): 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120, 300, 600 s.
* **Upload size** (`mstar_upload_size_bytes`): 1, 4, 16, 32, 64, 128, 256, 512 KiB, then 1, 2, 4, 8, 16, 32, 64, 128, 256, 1024 MiB.
* **Step** (`mstar_step_seconds`): 0.0005, 0.001, 0.002, 0.003, 0.005, 0.0075, 0.01, 0.015, 0.02, 0.03, 0.05, 0.075, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30 s.
* **Batch** (`mstar_batch_size`): 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 rows.
* **Transfer** (`mstar_transfer_seconds`): 10, 25, 50, 100, 250, 500 µs, then 1, 2.5, 5, 10, 25, 50, 100, 250, 500 ms, then 1, 2.5, 5, 10 s.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.