> For the complete documentation index, see [llms.txt](https://docs.seldon.ai/mpm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seldon.ai/mpm/visualizing-metrics/vizualization-grafana.md).

# Visualization in Grafana

{% hint style="info" %}
Instructions related to the Grafana UI are applicable to Grafana v11.3.0.
{% endhint %}

## Dashboards Configuration

Visualizing Metrics in Grafana requires a third-party plugin, such as [**Infinity** plugin](https://grafana.com/grafana/plugins/yesoreyeram-infinity-datasource/), which enables Grafana to query various data sources, including REST APIs.\
Follow the instructions below to configure Grafana and its dependencies.

{% stepper %}
{% step %}

#### Install the `Infinity` Plugin

* Open your Grafana UI instance.
* Navigate to **Administration** > **Plugins** (`/grafana/plugins`).
* Search for **"Infinity"**.
* Click on **Install** to add the plugin to your Grafana instance.

Alternatively, you can install the plugin using the Grafana CLI by running:

```bash
grafana cli plugins install yesoreyeram-infinity-datasource
```

Check for other installation methods in the plugin's ["Installation" documentation](https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/setup/installation/).
{% endstep %}

{% step %}

#### Add and Set Up New Data Source

* In the Grafana UI, go to **Connections** > **Data Sources** (`/grafana/connections/datasources`).
* Click `Add new data source` and search for the `Infinity` plugin to open data source configuration page.
* Under `URL, Headers & Params` for the `Infinity` plugin, configure the **Base URL** field.
  * For example, if metrics are available by this URL `http://<IP address>/metrics-server/api/v1/metrics/pipeline/classification`, configure **Base URL** as `http://<IP address>/metrics-server`.
  * Bear in mind, the URL should be accessible from the Grafana instance and the `/metrics-server` path comes from the Kubernetes `VirtualService` (`.spec.http.match.uri.prefix`) resource that should have been created when installing the Metrics Server via Helm.
* Save the data source configuration.
  {% endstep %}

{% step %}

#### Import the Dashboard JSON

Use these instructions to import the dashboard provided below to visualize [classification metrics](#classification-metrics-dashboard) or [regression metrics](#regression-metrics-dashboard).

1. Navigate to **Dashboards** > **New** > **Import** page (`/grafana/dashboard/import`).
2. In the **Import Dashboard** page, paste and load the entire **JSON** configuration into the **Dashboard JSON** field.
3. During the import process, Grafana will ask for a data source. The imported dashboard is configured to use the **Infinity** plugin. Under **"Datasource"**, ensure the **Infinity** data source is selected.
4. Once the correct data source is selected, proceed to click **Import**.
   {% endstep %}

{% step %}

#### Verify Dashboard Variables

Ensure you choose the correct **namespace**, **pipeline name**, **model name**, and **interval**.

* **namespace** contains Namespaces retrieved from the [subscriptions](/mpm/getting-started/model-subscriptions.md).
* **Pipeline Name** contains pipelines deployed within the *chosen namespace*.
* **Model Name** contains models that are part of the *deployed pipeline*.
* **Interval (`interval`)** contains predefined [interval values](/mpm/supported-metrics/calculating-metrics.md#interval).

If you need to modify the variables (for example, to change the list of predefined intervals), you can do so in the Dashboard settings (gear icon in the top-right corner).
{% endstep %}

{% step %}

#### Configure Time Range

By default, the dashboard time range is set to the last 6 hours. However, if you want to view metrics for a specific time range, you can configure it as follows:

1. Open the dashboard in Grafana.
2. Click on the time range selector (usually displayed as "Last 30 minutes", "Last 24 hours", or a custom time range).
3. On the left-hand side in **Absolute time range**, specify the **From** and **To** dates and times for the period you want to monitor.
   * The **From** time will define the starting point of the time range.
   * The **To** time will define the ending point of the time range.
4. After setting the absolute time range, click **Apply** to confirm the changes.
5. Change `Interval` dashboard variable if needed.

{% hint style="warning" %}
While the metrics API supports timezone offsets in datetime strings, you should configure the timezone in Grafana using the time range controls by clicking the Change time settings button.
{% endhint %}
{% endstep %}
{% endstepper %}

### Troubleshooting

<details>

<summary>Dashboard variables selects (namespace, pipeline or model name) are empty</summary>

The dashboard uses templating variables such as `namespace_var`, `pipelineName_var`, `modelName`, and `interval`. These variables are required for the correct functioning of the dashboard and must be configured properly to fetch data from the API.

In case you don't see any values inside dashboard variables, ensure that each variable has the appropriate query set up to fetch data.

1. Open the **Dashboard settings** (gear icon in the top-right corner).
2. Go to the **Variables** section and verify the following queries for the variables:
   * **namespace (`namespace_var`)**: fetches subscriptions using `/api/v1/pipeline/subscriptions` API and select `namespace` field from the API response rows.
   * **Pipeline Name (`pipelineName_var`)**: fetches subscriptions using `/api/v1/pipeline/subscriptions` API, filter rows by the chosen *namespace* and select `pipelineName` field using **UQL Query**.
   * **Model Name (`modelName`)**: fetches subscriptions using `/api/v1/pipeline/subscriptions` API, filter rows by the chosen *namespace* and *pipeline*, and select `modelName` field **using UQL Query**.

</details>

<details>

<summary>Dashboard does not display any data</summary>

If the dashboard does not display any data, verify the following:

* Ensure that the **Infinity** data source is [correctly set up](#add-and-set-up-new-data-source).
* Confirm that the API URL used in the dashboard's queries is correct and accessible from your Grafana instance.
* Make sure the variables are properly configured and returning valid data.
* If you’ve selected a namespace, pipeline, and model, and you see error warnings in the dashboard, try fetching the metrics API outside of Grafana to get a more detailed response error from the server. Currently, the Infinity plugin does not expose API server error descriptions.

{% hint style="info" %}
If there are no data points within the time bucket:

* `-1` will be returned for scalar metrics such as Accuracy, Recall, Precision, Specificity, F1, MSE, MAE, and RMSE.
* An **empty array** will be returned for non-scalar fields, such as the confusion matrix fields.
  {% endhint %}

The Grafana dashboard JSON models provided below are **configured to filter out `-1` values**, so they will not be reflected on the chart. This behavior can be modified in the Panel settings under the Transformations tab.

</details>

{% hint style="warning" %}
Be aware that the **Infinity** plugin doesn't expose API server errors. You could track [an open pull request](https://github.com/grafana/grafana-infinity-datasource/pull/1076) in the **Infinity** repository aimed to solved the issue.
{% endhint %}

Refer to the documentation of [Infinity plugin limitations](https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/#-known-limitations).

## Classification Metrics Dashboard

A **Classification Metrics** dashboard is available to monitor key performance metrics for classification models deployed with Core 2. This dashboard provides insights into [classification metrics](/mpm/supported-metrics/classification-metrics.md).

{% content-ref url="/pages/sYgXZpjy1mvffYCayTqK" %}
[Classification Metrics](/mpm/supported-metrics/classification-metrics.md)
{% endcontent-ref %}

Use the [instructions above](#import-the-dashboard-json) to import and configure the dashboard configuration JSON for classification metrics provided below:

{% file src="/files/XgwLYfFKbxhqkeYDdORi" %}

![Example of a Classification Metrics dashboard using test data](/files/1Ntzle4bB1PKDlxkcDlc)

## Regression Metrics Dashboard

A **Regression Metrics** dashboard is available to monitor key performance metrics for regression models deployed with Core 2. This dashboard provides insights into [regression metrics](/mpm/supported-metrics/regression-metrics.md).

{% content-ref url="/pages/1wN6PkcfMEZ02vQRRWgq" %}
[Regression Metrics](/mpm/supported-metrics/regression-metrics.md)
{% endcontent-ref %}

Use the [instructions above](#import-the-dashboard-json) to import and configure the dashboard configuration JSON for regression metrics provided below:

{% file src="/files/pBwVIcC3fz5OvYacyXqw" %}

![Example of a Regression Metrics dashboard using test data](/files/VeADu2a9bHDhwpjYnDU0)
