# Monitor Endpoints

Track custom metrics from your deployment endpoints by printing JSON metadata. Valohai automatically collects and visualizes these metrics.

### Collect metrics

Print JSON with `vh_metadata` to log metrics from your endpoint:

```python
import json

print(
    json.dumps(
        {
            "vh_metadata": {
                "accuracy": 0.9247,
                "best_guess": "dog",
                "confidence": 0.87,
            },
        },
    ),
)
```

Valohai parses this output and makes it available for visualization.

### View metrics

Access deployment metrics from your deployment version:

1. Open the **Deployment** tab
2. Select your deployment
3. Click on a version
4. View metrics in the **Monitoring** tab

**Available visualizations:**

* Time series charts (metrics over time)
* Histograms (distribution of values)
* Request logs (individual predictions)

### Common metrics to track

**Model performance:**

```python
print(
    json.dumps(
        {
            "vh_metadata": {
                "prediction_confidence": 0.94,
                "processing_time_ms": 23,
            },
        },
    ),
)
```

**Business metrics:**

```python
print(
    json.dumps(
        {
            "vh_metadata": {
                "fraud_detected": True,
                "transaction_amount": 1250.00,
            },
        },
    ),
)
```

**System metrics:**

```python
import time

start = time.time()
# ... inference code ...
duration = time.time() - start

print(
    json.dumps(
        {
            "vh_metadata": {
                "inference_latency_ms": int(duration * 1000),
            },
        },
    ),
)
```

### View endpoint logs

Access full logs for debugging or detailed inspection:

1. Navigate to your deployment version
2. Select an endpoint
3. Click **Log** tab
4. Filter by time range or search for specific events

***

**Next:** Learn how to [troubleshoot failing endpoints](https://github.com/valohai/dokuhai/blob/main/docs/debug.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.valohai.com/serving-your-models/real-time-endpoints/monitor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
