# `vllm_mlx.metrics`

Prometheus-first server metrics for vllm-mlx.

[View the complete module source at #L1-L532](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L1-L532).

## API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

::: vllm_mlx.metrics
    options:
      members:
        - _bool_str
        - _coerce_float
        - _coerce_int
        - InferenceTracker
        - MetricsCollector
        - metrics
      filters: []
      show_if_no_docstring: true

## Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

<details class="api-contract" id="contract-vllm_mlx.metrics._bool_str" markdown="1">
<summary><code>vllm_mlx.metrics._bool_str</code> · function</summary>

```python
vllm_mlx.metrics._bool_str(value: bool) -> str
```

Function `_bool_str` returns `'true' if value else 'false'`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `bool` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `str`
- Direct return expressions: `'true' if value else 'false'`

**Exceptions and behavior**

Function `_bool_str` returns `'true' if value else 'false'`.
No direct `raise` statement appears in this definition.

[View source #L17-L18](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L17-L18).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics._coerce_float" markdown="1">
<summary><code>vllm_mlx.metrics._coerce_float</code> · function</summary>

```python
vllm_mlx.metrics._coerce_float(value: Any, default: float = 0.0) -> float
```

Function `_coerce_float` calls `float`; has 2 explicit return paths.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Any` | `yes` | `none` | Required positional or keyword input. |
| `default` | `float` | `no` | `0.0` | Optional positional or keyword input; defaults to `0.0`. |

**Returns**

- Type: `float`
- Direct return expressions: `default`; `float(value)`

**Exceptions and behavior**

Function `_coerce_float` calls `float`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L21-L27](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L21-L27).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics._coerce_int" markdown="1">
<summary><code>vllm_mlx.metrics._coerce_int</code> · function</summary>

```python
vllm_mlx.metrics._coerce_int(value: Any, default: int = 0) -> int
```

Function `_coerce_int` calls `int`; has 2 explicit return paths.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Any` | `yes` | `none` | Required positional or keyword input. |
| `default` | `int` | `no` | `0` | Optional positional or keyword input; defaults to `0`. |

**Returns**

- Type: `int`
- Direct return expressions: `default`; `int(value)`

**Exceptions and behavior**

Function `_coerce_int` calls `int`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L30-L36](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L30-L36).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.InferenceTracker" markdown="1">
<summary><code>vllm_mlx.metrics.InferenceTracker</code> · class</summary>

```python
vllm_mlx.metrics.InferenceTracker(collector: 'MetricsCollector | None', endpoint: str, stream: bool, start_time: float = field(default_factory=time.perf_counter), _finished: bool = False, _ttft_observed: bool = False)
```

Request-scoped inference timing and token accounting.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `collector` | `'MetricsCollector \| None'` | `yes` | `none` | Required constructor field. |
| `endpoint` | `str` | `yes` | `none` | Required constructor field. |
| `stream` | `bool` | `yes` | `none` | Required constructor field. |
| `start_time` | `float` | `no` | `field(default_factory=time.perf_counter)` | Optional constructor field; defaults to `field(default_factory=time.perf_counter)`. |
| `_finished` | `bool` | `no` | `False` | Optional constructor field; defaults to `False`. |
| `_ttft_observed` | `bool` | `no` | `False` | Optional constructor field; defaults to `False`. |

**Returns**

- Constructs: `vllm_mlx.metrics.InferenceTracker`

**Exceptions and behavior**

Class `InferenceTracker` declares 2 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L40-L81](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L40-L81).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.InferenceTracker.observe_ttft" markdown="1">
<summary><code>vllm_mlx.metrics.InferenceTracker.observe_ttft</code> · method</summary>

```python
vllm_mlx.metrics.InferenceTracker.observe_ttft() -> None
```

Record time to first token once for this inference request.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `InferenceTracker.observe_ttft` updates `self._ttft_observed`; calls `self.collector.observe_ttft`, `time.perf_counter`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L50-L60](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L50-L60).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.InferenceTracker.finish" markdown="1">
<summary><code>vllm_mlx.metrics.InferenceTracker.finish</code> · method</summary>

```python
vllm_mlx.metrics.InferenceTracker.finish(*, result: str, prompt_tokens: int = 0, completion_tokens: int = 0) -> None
```

Record terminal latency and token counts once for this request.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `result` | `str` | `yes` | `none` | Required keyword-only input. |
| `prompt_tokens` | `int` | `no` | `0` | Optional keyword-only input; defaults to `0`. |
| `completion_tokens` | `int` | `no` | `0` | Optional keyword-only input; defaults to `0`. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `InferenceTracker.finish` updates `self._finished`; calls `self.collector.observe_inference`, `time.perf_counter`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L62-L81](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L62-L81).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector</code> · class</summary>

```python
vllm_mlx.metrics.MetricsCollector()
```

Lazy Prometheus-backed metrics collector.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.metrics.MetricsCollector`

**Exceptions and behavior**

Class `MetricsCollector` declares 11 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L84-L529](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L84-L529).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.__init__" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.__init__</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.__init__() -> None
```

Method `MetricsCollector.__init__` updates `self._enabled`, `self._lock`, `self._prom`; calls `threading.Lock`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `None`

**Exceptions and behavior**

Method `MetricsCollector.__init__` updates `self._enabled`, `self._lock`, `self._prom`; calls `threading.Lock`.
No direct `raise` statement appears in this definition.

[View source #L87-L90](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L87-L90).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.enabled" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.enabled</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.enabled() -> bool
```

Return whether metric collection is enabled.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `bool`
- Direct return expressions: `self._enabled`

**Exceptions and behavior**

Method `MetricsCollector.enabled` returns `self._enabled`.
No direct `raise` statement appears in this definition.

[View source #L93-L96](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L93-L96).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.configure" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.configure</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.configure(*, enabled: bool) -> None
```

Enable or disable collection and lazily initialize Prometheus state.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enabled` | `bool` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `MetricsCollector.configure` updates `self._enabled`; calls `self._init_prometheus`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L98-L105](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L98-L105).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector._init_prometheus" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector._init_prometheus</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector._init_prometheus() -> None
```

Method `MetricsCollector._init_prometheus` updates `self._prom`; calls `CollectorRegistry`, `Counter`, `Histogram`, `Gauge`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `None`

**Exceptions and behavior**

Method `MetricsCollector._init_prometheus` updates `self._prom`; calls `CollectorRegistry`, `Counter`, `Histogram`, `Gauge`.
No direct `raise` statement appears in this definition.

[View source #L107-L291](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L107-L291).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.track_inference" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.track_inference</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.track_inference(endpoint: str, *, stream: bool) -> InferenceTracker
```

Create request-scoped inference timing state for an endpoint.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `endpoint` | `str` | `yes` | `none` | Required positional or keyword input. |
| `stream` | `bool` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `InferenceTracker`
- Direct return expressions: `InferenceTracker(None, endpoint, stream)`; `InferenceTracker(self, endpoint, stream)`

**Exceptions and behavior**

Method `MetricsCollector.track_inference` calls `InferenceTracker`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L293-L298](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L293-L298).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.observe_http_start" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.observe_http_start</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.observe_http_start(*, method: str, path: str) -> None
```

Increment the in-flight request gauge for a normalized route.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `method` | `str` | `yes` | `none` | Required keyword-only input. |
| `path` | `str` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `MetricsCollector.observe_http_start` calls `self._prom['http_requests_in_flight'].labels(method=method, path=path).inc`, `self._prom['http_requests_in_flight'].labels`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L300-L305](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L300-L305).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.observe_http_finish" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.observe_http_finish</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.observe_http_finish(*, method: str, path: str, status_code: int, duration: float) -> None
```

Record an HTTP result and decrement its in-flight gauge.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `method` | `str` | `yes` | `none` | Required keyword-only input. |
| `path` | `str` | `yes` | `none` | Required keyword-only input. |
| `status_code` | `int` | `yes` | `none` | Required keyword-only input. |
| `duration` | `float` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `MetricsCollector.observe_http_finish` calls `self._prom['http_requests_in_flight'].labels(method=method, path=path).dec`, `self._prom['http_requests_in_flight'].labels`, `self._prom['http_requests_total'].labels(method=method, path=path, status_code=str(status_code)).inc`, `self._prom['http_requests_total'].labels`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L307-L328](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L307-L328).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.observe_inference" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.observe_inference</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.observe_inference(*, endpoint: str, stream: bool, result: str, duration: float, prompt_tokens: int, completion_tokens: int) -> None
```

Record one terminal inference outcome, latency, and token totals.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `endpoint` | `str` | `yes` | `none` | Required keyword-only input. |
| `stream` | `bool` | `yes` | `none` | Required keyword-only input. |
| `result` | `str` | `yes` | `none` | Required keyword-only input. |
| `duration` | `float` | `yes` | `none` | Required keyword-only input. |
| `prompt_tokens` | `int` | `yes` | `none` | Required keyword-only input. |
| `completion_tokens` | `int` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `MetricsCollector.observe_inference` calls `_bool_str`, `self._prom['inference_requests_total'].labels(endpoint=endpoint, stream=stream_label, result=result).inc`, `self._prom['inference_requests_total'].labels`, `self._prom['inference_request_duration_seconds'].labels(endpoint=endpoint, stream=stream_label).observe`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L330-L363](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L330-L363).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.observe_ttft" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.observe_ttft</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.observe_ttft(*, endpoint: str, stream: bool, value: float) -> None
```

Observe time to first token for a streaming or buffered request.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `endpoint` | `str` | `yes` | `none` | Required keyword-only input. |
| `stream` | `bool` | `yes` | `none` | Required keyword-only input. |
| `value` | `float` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `MetricsCollector.observe_ttft` calls `self._prom['inference_ttft_seconds'].labels(endpoint=endpoint, stream=_bool_str(stream)).observe`, `self._prom['inference_ttft_seconds'].labels`, `_bool_str`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L365-L373](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L365-L373).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector._update_engine_gauges" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector._update_engine_gauges</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector._update_engine_gauges(*, engine: Any | None, mcp_manager: Any | None) -> None
```

Method `MetricsCollector._update_engine_gauges` calls `engine.get_stats`, `self._prom['model_loaded'].set`, `stats.get`, `self._prom['engine_type'].labels(engine_type=engine_type).set`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `engine` | `Any \| None` | `yes` | `none` | Required keyword-only input. |
| `mcp_manager` | `Any \| None` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `None`

**Exceptions and behavior**

Method `MetricsCollector._update_engine_gauges` calls `engine.get_stats`, `self._prom['model_loaded'].set`, `stats.get`, `self._prom['engine_type'].labels(engine_type=engine_type).set`.
No direct `raise` statement appears in this definition.

[View source #L375-L507](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L375-L507).

</details>

<details class="api-contract" id="contract-vllm_mlx.metrics.MetricsCollector.render_metrics" markdown="1">
<summary><code>vllm_mlx.metrics.MetricsCollector.render_metrics</code> · method</summary>

```python
vllm_mlx.metrics.MetricsCollector.render_metrics(*, engine: Any | None, mcp_manager: Any | None) -> tuple[bytes, str]
```

Refresh runtime gauges and render Prometheus exposition bytes.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `engine` | `Any \| None` | `yes` | `none` | Required keyword-only input. |
| `mcp_manager` | `Any \| None` | `yes` | `none` | Required keyword-only input. |

**Returns**

- Type: `tuple[bytes, str]`
- Direct return expressions: `(self._prom['generate_latest'](self._prom['registry']), self._prom['content_type'])`

**Exceptions and behavior**

Method `MetricsCollector.render_metrics` calls `RuntimeError`, `self._init_prometheus`, `self._update_engine_gauges`, `self._prom['generate_latest']`; can raise `RuntimeError`; returns `(self._prom['generate_latest'](self._prom['registry']), self._prom['content_type'])`.
Directly raised exceptions: `RuntimeError`.

[View source #L509-L529](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L509-L529).

</details>

## Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

| Symbol | Kind | Signature and inputs | What it does | Source |
| --- | --- | --- | --- | --- |
| [`_bool_str`](#contract-vllm_mlx.metrics._bool_str) | function | `_bool_str(value: bool) -> str` | Function `_bool_str` returns `'true' if value else 'false'`. | [#L17-L18](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L17-L18) |
| [`_coerce_float`](#contract-vllm_mlx.metrics._coerce_float) | function | `_coerce_float(value: Any, default: float = 0.0) -> float` | Function `_coerce_float` calls `float`; has 2 explicit return paths. | [#L21-L27](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L21-L27) |
| [`_coerce_int`](#contract-vllm_mlx.metrics._coerce_int) | function | `_coerce_int(value: Any, default: int = 0) -> int` | Function `_coerce_int` calls `int`; has 2 explicit return paths. | [#L30-L36](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L30-L36) |
| [`InferenceTracker`](#contract-vllm_mlx.metrics.InferenceTracker) | class | `InferenceTracker(collector: 'MetricsCollector \| None', endpoint: str, stream: bool, start_time: float = field(default_factory=time.perf_counter), _finished: bool = False, _ttft_observed: bool = False)` | Request-scoped inference timing and token accounting. | [#L40-L81](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L40-L81) |
| [`InferenceTracker.observe_ttft`](#contract-vllm_mlx.metrics.InferenceTracker.observe_ttft) | method | `InferenceTracker.observe_ttft() -> None` | Record time to first token once for this inference request. | [#L50-L60](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L50-L60) |
| [`InferenceTracker.finish`](#contract-vllm_mlx.metrics.InferenceTracker.finish) | method | `InferenceTracker.finish(*, result: str, prompt_tokens: int = 0, completion_tokens: int = 0) -> None` | Record terminal latency and token counts once for this request. | [#L62-L81](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L62-L81) |
| [`MetricsCollector`](#contract-vllm_mlx.metrics.MetricsCollector) | class | `MetricsCollector()` | Lazy Prometheus-backed metrics collector. | [#L84-L529](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L84-L529) |
| [`MetricsCollector.__init__`](#contract-vllm_mlx.metrics.MetricsCollector.__init__) | method | `MetricsCollector.__init__() -> None` | Method `MetricsCollector.__init__` updates `self._enabled`, `self._lock`, `self._prom`; calls `threading.Lock`. | [#L87-L90](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L87-L90) |
| [`MetricsCollector.enabled`](#contract-vllm_mlx.metrics.MetricsCollector.enabled) | method | `MetricsCollector.enabled() -> bool` | Return whether metric collection is enabled. | [#L93-L96](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L93-L96) |
| [`MetricsCollector.configure`](#contract-vllm_mlx.metrics.MetricsCollector.configure) | method | `MetricsCollector.configure(*, enabled: bool) -> None` | Enable or disable collection and lazily initialize Prometheus state. | [#L98-L105](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L98-L105) |
| [`MetricsCollector._init_prometheus`](#contract-vllm_mlx.metrics.MetricsCollector._init_prometheus) | method | `MetricsCollector._init_prometheus() -> None` | Method `MetricsCollector._init_prometheus` updates `self._prom`; calls `CollectorRegistry`, `Counter`, `Histogram`, `Gauge`. | [#L107-L291](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L107-L291) |
| [`MetricsCollector.track_inference`](#contract-vllm_mlx.metrics.MetricsCollector.track_inference) | method | `MetricsCollector.track_inference(endpoint: str, *, stream: bool) -> InferenceTracker` | Create request-scoped inference timing state for an endpoint. | [#L293-L298](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L293-L298) |
| [`MetricsCollector.observe_http_start`](#contract-vllm_mlx.metrics.MetricsCollector.observe_http_start) | method | `MetricsCollector.observe_http_start(*, method: str, path: str) -> None` | Increment the in-flight request gauge for a normalized route. | [#L300-L305](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L300-L305) |
| [`MetricsCollector.observe_http_finish`](#contract-vllm_mlx.metrics.MetricsCollector.observe_http_finish) | method | `MetricsCollector.observe_http_finish(*, method: str, path: str, status_code: int, duration: float) -> None` | Record an HTTP result and decrement its in-flight gauge. | [#L307-L328](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L307-L328) |
| [`MetricsCollector.observe_inference`](#contract-vllm_mlx.metrics.MetricsCollector.observe_inference) | method | `MetricsCollector.observe_inference(*, endpoint: str, stream: bool, result: str, duration: float, prompt_tokens: int, completion_tokens: int) -> None` | Record one terminal inference outcome, latency, and token totals. | [#L330-L363](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L330-L363) |
| [`MetricsCollector.observe_ttft`](#contract-vllm_mlx.metrics.MetricsCollector.observe_ttft) | method | `MetricsCollector.observe_ttft(*, endpoint: str, stream: bool, value: float) -> None` | Observe time to first token for a streaming or buffered request. | [#L365-L373](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L365-L373) |
| [`MetricsCollector._update_engine_gauges`](#contract-vllm_mlx.metrics.MetricsCollector._update_engine_gauges) | method | `MetricsCollector._update_engine_gauges(*, engine: Any \| None, mcp_manager: Any \| None) -> None` | Method `MetricsCollector._update_engine_gauges` calls `engine.get_stats`, `self._prom['model_loaded'].set`, `stats.get`, `self._prom['engine_type'].labels(engine_type=engine_type).set`. | [#L375-L507](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L375-L507) |
| [`MetricsCollector.render_metrics`](#contract-vllm_mlx.metrics.MetricsCollector.render_metrics) | method | `MetricsCollector.render_metrics(*, engine: Any \| None, mcp_manager: Any \| None) -> tuple[bytes, str]` | Refresh runtime gauges and render Prometheus exposition bytes. | [#L509-L529](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/metrics.py#L509-L529) |
