# How to create Grafana Dashboard for Frends

[Grafana](https://grafana.com/) is a powerful open-source platform for visualizing and analyzing data, and when you connect it to the Frends Platform API, you can create detailed, real-time monitoring dashboards for your Frends Processes. This guide walks you through setting up a production-ready dashboard.

## Prerequisites

Before you begin, make sure you have a running Grafana instance (version 7.0 or newer). You'll also need the [Frends Platform API enabled for your Tenant](https://app.gitbook.com/s/1H5SQ92uIfBOYNIeoUAc/frends-platform-api/how-to-enable-frends-platform-api) with the Grafana's host server IP address whitelisted.

You'll need your Azure AD App Registration credentials handy. Specifically, you'll need your **Tenant ID**, **Application (client) ID**, **Client Secret**, and the **Application ID URI** (which typically looks like `api://<client-id>` or a custom URI). These credentials secure the API connection and enable authentication. These should have been created during the Frends Platform API enablement.

## Install the Infinity Plugin for Grafana

The Infinity plugin natively supports the OAuth2 authentication, which is used by Frends Platform API. The plugin's main feature is automatic refreshing of the token—no manual token updates needed.

You can find and install the **Infinity** plugin directly from Grafana under **Administration → Plugins**.

If you prefer using the Command Line Interface, to install the plugin, run this command in your terminal:

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

After installation, restart your Grafana server to activate the plugin:

```shell
systemctl restart grafana-server
```

## Configure the Frends Platform API as a Data Source with OAuth2

Now let's connect Grafana to the Frends Platform API. In Grafana, navigate to **Connections → Data sources** and click **Add data source**. Search for and select **Infinity**.

Give your data source a name—something like `Frends Platform API` works well. Then head to the **Authentication** section and select **OAuth2 Client Credentials** as the authentication type.

You'll need to fill in a few fields here. Set the **Token URL** to `https://login.microsoftonline.com/<your-tenant-id>/oauth2/v2.0/token`, replacing `<your-tenant-id>` with your actual Azure AD tenant ID. Enter your **Client ID** and **Client Secret** from your Azure AD app registration. For **Scopes**, enter `<your-application-id-uri>/.default`—this typically looks like `api://12345678-1234-1234-1234-123456789012/.default`.

For added security, you can specify **Allowed hosts** as `<your-tenant>.frendsapp.com` under additional settings.

Click **Save & test** to confirm everything is working. You should see a "Success" message indicating the OAuth2 authentication is properly configured.

## Create a Dashboard and Query Agent Group Instances

Let's create your first dashboard panel. This panel will display the latest Process Instance executions for a specific Agent Group.

Before we start in Grafana, you'll need the target Agent Group's ID for the query from Frends.&#x20;

Log in to your Frends Tenant. After logging in, head to URL `https://<your-tenant>.frendsapp.com/api/environment/details` to obtain a list of Environments and Agent Groups in your Frends Tenant as JSON. From the JSON, find the wanted Environment and Agent Group, and select the Agent Group's `id` value and keep it handy.

{% hint style="info" %}
We recommend creating a **separate dashboard for each Agent Group**. This keeps your monitoring focused and organized, allowing you to set specific refresh rates, alerts, and visualizations tailored to each environment—whether it's Production, Development, or Testing.
{% endhint %}

After the Agent Group ID is obtained for this example, go to **Dashboards** in Grafana and click **New Dashboard**, then **Add visualization**. In the panel editor, select your `Frends Platform API` data source.

Now configure the query. Set **Type** to `JSON`, **Parser** to `Backend`, **Source** to `URL`, and **Format** to `Table`. For the **URL**, enter `https://<your-tenant>.frendsapp.com/api/v1/instances/<your-agent-group-id>`—make sure to replace `<your-agent-group-id>` with the actual ID you copied earlier. Set the **Method** to `GET`.

If you want to limit the results, click **URL options** and add a parameter like `pageSize=100`. The Infinity plugin will automatically parse the JSON response and display it as a table.

## Transform and Visualize the Data

Once you have data flowing in, you can refine how it's displayed. Head to the **Transform** tab where you can organize fields—hide unnecessary columns, rename them, or reorder them to show what matters most (like `id`, `processName`, `status`, `started`, and `durationInMs`). You can also apply filters based on field values or format timestamps and numbers to make them more readable.

For the visualization type, choose what works best for your needs. A **Table** is perfect for viewing a detailed list of Process Instances. Use **Stat** to show a single value like the total count of failed instances. **Time series** lets you plot execution counts or duration over time, and **Bar gauge** works great for visualizing metrics like execution duration.

## Save the Dashboard

Once you're happy with your panel, click **Apply** to save the configuration. Then click the **Save** icon at the top of the dashboard and give it a descriptive name—something like "Production Agent Group - Process Instances" helps you identify it quickly later.

Congratulations! You now have a production-ready Frends monitoring dashboard with automatic OAuth2 token refresh. No more manually updating tokens every hour.

## Additional Configuration Examples

### Monitor Failed Executions for an Agent Group

Want to keep a close eye on failures? Create a panel that monitors only failed process instances for your Agent Group. Use the endpoint `https://<your-tenant>.frendsapp.com/api/v1/instances/<your-agent-group-id>` with a GET method, and add the query parameter `stateFilter=ShowFailed`.

Display this as a table with a red color scheme to make failures stand out. Set the refresh interval to every 30 seconds so you catch issues quickly, and configure a threshold alert when the count exceeds a certain number.

### Monitor Multiple Status Types

For a comprehensive view, create multiple panels on the same dashboard showing different execution statuses.

Set up a **Failed Instances** panel using `https://<your-tenant>.frendsapp.com/api/v1/instances/<your-agent-group-id>?stateFilter=ShowFailed` displayed as a Stat with a red threshold. Add a **Running Instances** panel with `stateFilter=ShowRunning` shown in blue, and a **Completed Instances** panel with `stateFilter=ShowFinished` in green. This gives you an at-a-glance overview of your system's health.

### Dashboard Organization by Environment

Smart organization makes all the difference. Create separate dashboards for each environment to keep things clean and focused.

Your **Production Dashboard** should monitor production Agent Groups with strict alerts and shorter refresh intervals (like 30 seconds), focusing on failed executions and performance metrics. For your **Development Dashboard**, use longer refresh intervals to reduce API load and focus on execution logs and debugging information. Your **Testing/QA Dashboard** can track test execution success rates and monitor specific test processes.
