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

# Grafana

> Connect Grafana with a Viewer service account so agents can search dashboards, query metrics and logs, and check alert rules

Connect a Grafana instance so [CloudThinker](https://docs.cloudthinker.io/guide/agents/overview.md) can work from the dashboards, data sources, and alert rules your team already has. Agents can find the right dashboard, run Prometheus or Loki queries through Grafana, and tell you which alerts are firing, without you copying panels into chat. The connection signs in with a **service account token**, a non-human Grafana identity you create and scope to the **Viewer** role.

## Supported platforms

| Platform | Supported |
| - | - |
| **Grafana OSS** | Yes, on 9.1 or later (service accounts became generally available in 9.1) |
| **Grafana Enterprise** | Yes |
| **Grafana Cloud** | Yes |

## Prerequisites

* A Grafana instance reachable from the public internet over HTTPS. Connections run from CloudThinker Cloud, so a private instance needs one of the options in [Reaching private services](https://docs.cloudthinker.io/guide/connections/overview.md#reaching-private-services). If you firewall it, allow CloudThinker's egress IPs. These docs don't publish CloudThinker's egress IP list: ask your CloudThinker contact, or [contact us](https://cloudthinker.io/contact).
* A valid, publicly trusted TLS certificate. Self-signed certificates fail.
* Grafana admin access to create a service account.
* One connection per Grafana organization. A service account sees only the organization it was created in, so for several orgs, create a service account in each and add a connection for each.
* The **Admin** role in your CloudThinker workspace, which can add and edit connections. See [Roles](https://docs.cloudthinker.io/guide/security/roles.md).

## Setup

**1. Create a Viewer service account**

In Grafana, go to **Administration → Users and access → Service accounts** and click **Add service account**. Set:

* **Display name**: `cloudthinker-readonly`
* **Role**: **Viewer**

Click **Create**.

**2. Generate a token**

On the new service account's page, click **Add service account token**, name it (for example `cloudthinker`), set an expiration such as 90 days, and click **Generate token**. When the token expires, the connection fails with a 401 until you replace it. See [Token expired](#troubleshooting).

Copy the token now. It starts with `glsa_`, and Grafana won't show it again.

**3. Add the connection in CloudThinker**

Open **More → Workspace settings → Connections**, stay on the **Builtin Connections** tab, and select **Grafana**. Fill in:

* **GRAFANA\_URL**: your instance's base URL, such as `https://grafana.example.com` or `https://your-stack.grafana.net`
* **GRAFANA\_SERVICE\_ACCOUNT\_TOKEN**: the `glsa_` token
* **Alias** and **Description**: optional. Agents read the description to pick the right instance, so name the org or environment if you add more than one

Click **Connect**.

**Success state:** the connection shows **Connecting** and **Verifying**, then **Connected**. If verification fails, it shows **Failed** and an error message appears. Match the message to [Troubleshooting](#troubleshooting).

## Connection details

| Field | Required | Example | Description |
| - | - | - | - |
| **GRAFANA\_URL** | Yes | `https://grafana.example.com` | Base URL of the instance, the address you open in a browser |
| **GRAFANA\_SERVICE\_ACCOUNT\_TOKEN** | Yes | `glsa_...` | Token for the service account agents act as |

## Required permissions

| Role | What agents get | Use it when |
| - | - | - |
| **Viewer** | Search and read dashboards and folders, query data sources, read alert rules and annotations | Investigation. Recommended |
| **Editor** | Viewer, plus changing dashboards, annotations, and alert rules. Each change goes through [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md) | Only if you want agents to make those changes |

Agents see only what the service account can see. If a dashboard folder has restricted permissions, add the service account to that folder or agents won't find its dashboards.

> [!TIP]
>
> Keep the service account on **Viewer**. Grafana then refuses any change on its side, whatever an agent asks for.

## Agent capabilities

| Capability | What agents can do |
| - | - |
| **Dashboards and folders** | Search by name or tag, read a dashboard's panels and queries, and run a panel's query |
| **Metrics** | Run PromQL against Prometheus data sources, with label and metric discovery |
| **Logs** | Run LogQL against Loki data sources, and search logs across supported data sources |
| **Other data sources** | Query Elasticsearch, CloudWatch, and ClickHouse data sources configured in Grafana |
| **Alerting** | List alert rules and their state, and show which are firing |
| **Annotations** | Read annotations, such as deploy markers, for the time around an issue |
| **Grafana Cloud features** | Where your stack has them: Grafana Incident, OnCall schedules, Sift investigations, and Pyroscope profiles |

Agents query through Grafana, so a data source only works if it's configured in your Grafana instance and the service account can use it.

When Grafana is connected, [Resolve](https://docs.cloudthinker.io/guide/incident/overview.md) can also read your alert rules and query metric ranges while it investigates an incident. Sending Grafana alerts into Resolve is a separate webhook setup: see [Webhook integrations](https://docs.cloudthinker.io/guide/incident/webhook-integrations/overview.md).

### Verify the connection

```text theme={null}
List the Grafana alert rules that are firing right now, and the data sources configured in Grafana
```

Expect the names and states of firing rules (or a note that none are firing), then each data source with its type, such as Prometheus or Loki.

### Example prompts

```text theme={null}
Find the Grafana dashboard for the checkout service and summarize what its panels show for the last hour
Using Grafana's Prometheus data source, which pods restarted most in the last 24 hours?
Search Loki through Grafana for errors from the payments app since 09:00 and group them by message
```

## Write access

The connection can call Grafana tools that change things, such as editing a dashboard, adding an annotation, or changing an alert rule. Any call that changes something goes through [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md), and Grafana only allows it if the service account's role does. With **Viewer**, Grafana refuses all of them.

Every change an agent makes goes through your workspace's [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md) first. On the default **Auto · Rules + AI · Ask me** mode, AI judgment can let a safe change run without asking — and an Allow Rule can too, once CloudThinker turns on [Rule enforcement](https://docs.cloudthinker.io/guide/approvals/rules.md#troubleshooting) for your workspace. Choose **Manual** to approve every change yourself.

There's no **Allow writes** switch on this connection, so CloudThinker has no read-only setting of its own here. The service account's Grafana role is what blocks writes, so keep it on **Viewer** unless you want changes.

## Troubleshooting

> [accordion] Connection failed
>
> * Open **GRAFANA\_URL** from a browser outside your network to check it's reachable from the internet, or allow CloudThinker through your firewall.
> * Check that the TLS certificate is valid and not self-signed.
> * Use the base URL only, without a dashboard path.

> [accordion] Authentication failed or 401
>
> * Recheck the token. Copy it again if a character was lost.
> * Check that the token hasn't expired and the service account is enabled in **Administration → Users and access → Service accounts**.

> [accordion] Token expired
>
> Open the service account in Grafana, generate a new token, and paste it into **GRAFANA\_SERVICE\_ACCOUNT\_TOKEN** on the connection. Delete the old token in Grafana.

> [accordion] Agents can't find a dashboard you can see
>
> The dashboard sits in a folder the service account can't view. Grant the service account **View** on that folder.

> [accordion] A data source query fails
>
> Your own access in Explore doesn't prove the service account's. Check two things:
>
> * On Grafana Enterprise or Cloud, open the data source's **Permissions** tab and confirm the service account (or a role it has) can query it.
> * Test as the service account: `curl -H "Authorization: Bearer glsa_..." https://<grafana>/api/datasources`. If the data source is missing from the response, the service account can't use it.
>
> Agents can only query data sources that Grafana itself can query.

> [accordion] Incident, OnCall, or Sift requests fail
>
> Those are Grafana Cloud features. They work only if your stack has them turned on. Some Grafana Cloud apps have their own access roles, so if **Viewer** isn't enough, check the app's role settings for the service account in Grafana.

## Security

* **Least privilege** — grant only the permissions the agents need for your use case; start read-only and widen later.
* **Read-only by default** — use read-only credentials unless you want agents to make changes through this connection.
* **Rotate credentials** — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
* **Revoke on offboarding** — remove the credential at the provider when you delete a connection or a teammate leaves.

- **Viewer only**: give the CloudThinker service account **Viewer**, never **Admin**.
- **Expiring tokens**: set an expiration on every token and rotate it on your normal schedule.

## Related

> [card] [Prometheus](https://docs.cloudthinker.io/guide/connections/prometheus.md)
>
> Query Prometheus directly when it isn't behind Grafana.

> [card] [Webhook integrations](https://docs.cloudthinker.io/guide/incident/webhook-integrations/overview.md)
>
> Send Grafana alerts into Resolve so investigations start on their own.


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