> For the complete documentation index, see [llms.txt](https://docs.pagerly.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pagerly.io/sre-ai-agent/data-sources/grafana.md).

# Grafana

Connect Grafana to the Pagerly SRE Agent to search dashboards, check firing alerts, read annotations, and query Prometheus metrics.

## What the Agent Can Do

* Search dashboards by keyword and link straight to the matching ones
* Check which Grafana alerts are currently firing (or pending, or in no data)
* Read annotations from a recent time window, optionally filtered by tag — find deployment markers and incident notes around the time of the incident
* Run PromQL queries against a Prometheus datasource through Grafana's datasource proxy

## Setup Instructions

1. Log into your **Grafana instance**
2. Go to **Administration** (gear icon) > **Service accounts**
3. Click **Add service account**, give it a name (e.g., `Pagerly`)
4. Set the role to **Viewer** — the agent only reads, so Viewer is enough
5. Click **Add service account token**, then **Generate token**
6. In Pagerly, open [SRE Agent Integrations](https://workspace.pagerly.io/integrations/sre-agent), select **Grafana**, and paste the token and your Grafana URL

## Required Credentials

| Field           | Description                                                                   | Example                        |
| --------------- | ----------------------------------------------------------------------------- | ------------------------------ |
| **API Token**   | Grafana service account token                                                 | `glsa_...`                     |
| **Grafana URL** | Your Grafana instance URL. A dashboard URL also works; only the base is used. | `https://your-org.grafana.net` |

## Context Prompt Tips

The agent needs a datasource's **UID** to query metrics, and it can't look UIDs up on its own. Find it under **Connections** > **Data sources** > your Prometheus datasource (the last part of the page URL), and put it in the context prompt:

> *"Our main dashboards are in the SRE folder. Prometheus datasource UID is `prom-prod`. Key dashboards: api-latency, error-rates, k8s-overview. Deploys are annotated with the tag `deploy`."*

## Docs

* [Grafana HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/)
