Skip to main content

Grafana Integration

Connect Grafana to enable the AI agent to query dashboards, metrics, and alerts during investigations. You can also forward Grafana alerts to Autoheal via webhook so alerts are ingested, grouped, and available for triage in the Alerts page.

Capabilities

Once connected, the AI agent can:

CapabilityDescription
Query LogsQuery logs from Loki or VictoriaLogs data sources
Query MetricsFetch data from Prometheus and other metric sources
View DashboardsAccess dashboard panels and visualizations
Check AlertsReview alert rules and their current state
Alert Source WebhooksReceive Grafana firing and resolved alerts via webhook, including batched alert payloads
Search AnnotationsFind annotations marking events

Supported Log Backends

The Grafana integration auto-detects your log backend and uses the appropriate query tools:

BackendDatasource TypeQuery LanguageAuto-Detected
Grafana LokilokiLogQLYes
VictoriaLogsvictoriametrics-logs-datasourceLogsQLYes

No additional configuration is needed — the agent discovers available data sources automatically.

Prerequisites

  • A Grafana instance (Cloud or self-hosted)
  • Grafana 9+ with Unified Alerting enabled (required for alert-source webhooks)
  • A Service Account token or a legacy API key
  • Viewer or higher permissions

Setup

Both service account tokens (recommended) and legacy API keys are supported.

1
Create a Service Account
  1. Log in to your Grafana instance
  2. Navigate to AdministrationService accounts
  3. Click Add service account
  4. Name it (e.g., "Autoheal Integration")
  5. Assign the Viewer role
2
Generate API Token
  1. In the service account, click Add token
  2. Give it a name and set expiration (or no expiration)
  3. Copy the generated token immediately
3
Add Integration in Autoheal
  1. Go to Integrations in Autoheal
  2. Click Grafana
  3. Enter a name (e.g., "Production Grafana")
4
Configure Credentials

Enter the following:

  • URL: Your Grafana URL (e.g., https://your-org.grafana.net)
  • API Token: The service account token you created
5
Test and Save

Click Test Connection to verify, then Save.

Option B: Legacy API Key

Legacy API keys are deprecated in Grafana 9+ but still supported by this integration.

1
Generate an API Key
  1. Log in to your Grafana instance
  2. Navigate to ConfigurationAPI keys
  3. Click Add API key
  4. Name it (e.g., "Autoheal Integration")
  5. Set the role to Viewer (or higher)
  6. Set expiration as needed
  7. Copy the generated key immediately — it will not be shown again
2
Add Integration in Autoheal
  1. Go to Integrations in Autoheal
  2. Click Grafana
  3. Enter a name (e.g., "Production Grafana")
3
Configure Credentials

Enter the following:

  • URL: Your Grafana URL (e.g., https://grafana.your-company.com)
  • API Token: The legacy API key you created
4
Test and Save

Click Test Connection to verify, then Save.

note

Grafana is deprecating legacy API keys in favor of service account tokens. If your Grafana version supports service accounts, we recommend using Option A.

Required Permissions

The service account or API key needs:

PermissionWhy It's Needed
Viewer roleBasic read access to dashboards and data
Data source accessQuery underlying data sources
note

For self-hosted Grafana, ensure the service account or API key has access to the specific data sources you want to query.

Grafana Cloud vs Self-Hosted

Grafana Cloud

Use your Grafana Cloud URL:

https://your-org.grafana.net

Self-Hosted Grafana

Use your Grafana server URL:

https://grafana.your-company.com

Ensure the URL is accessible from Autoheal (check firewall rules).

Example Queries

Once connected, you can ask the AI agent:

Show me the request rate from the API dashboard
What alerts are currently firing in Grafana?
Get CPU metrics for the web servers from the last 30 minutes

Grafana Version Compatibility

The integration automatically handles different Grafana API versions. Grafana 11.x introduced changes to datasource proxy endpoints that are transparently managed by the agent.

Version Detection

The agent can detect your Grafana version to optimize API calls:

What version of Grafana are we using?

This returns version information and API compatibility mode.

Automatic Fallback

The integration uses version-aware endpoint selection with automatic fallback:

  • Grafana 11.x and later: Uses ID-based datasource proxy (primary), falls back to UID-based if needed
  • Grafana 10.x and earlier: Uses UID-based datasource proxy (primary), falls back to ID-based if needed

This ensures compatibility across different Grafana versions without requiring manual configuration.

Alert Source Setup

Grafana can also act as an alert source by forwarding alerts to Autoheal via webhook using Grafana Unified Alerting (Grafana 9+).

Configure Grafana as an Alert Source

1
Enable the Webhook in Autoheal
  1. Open your Grafana integration in Autoheal
  2. Go to the Alert Source tab
  3. Enable the webhook and copy the Webhook URL
  4. Optionally, enter a Webhook Signing Secret for additional authentication
2
Create a Contact Point in Grafana
  1. In Grafana, go to AlertingContact points
  2. Click Create contact point
  3. Name it anything for your own organization (for example, "Autoheal")
  4. Choose Webhook as the contact point type
  5. Paste the Webhook URL into the URL field
  6. Ensure HTTP Method is POST (not PUT)
  7. If you set a Webhook Signing Secret in Autoheal, expand Optional Webhook settings, set Authorization Header - Scheme to Bearer, and paste the same secret into Authorization Header - Credentials
  8. Save the contact point
3
Configure a Notification Policy
  1. Go to AlertingNotification policies
  2. Edit the default policy or create a new one
  3. Set the contact point to "Autoheal"
  4. Save the policy
4
Test the Integration

Create or trigger a test alert in Grafana to verify alerts appear in Autoheal's Alerts page. You should typically see new alert entries within seconds (timing can vary based on grouping settings).

note

Grafana Unified Alerting is available in Grafana 9 and later. Both Grafana Cloud and self-hosted instances are supported.

note

The Webhook Signing Secret is an optional second layer of authentication. The webhook URL already contains a unique secret for identifying your integration. Adding a signing secret provides additional verification via the Authorization header, ensuring only Grafana can send alerts to your endpoint.

tip

Grafana sends both firing and resolved state changes through the same webhook endpoint, and one delivery can include multiple alerts in the alerts[] array. Resolved alerts are processed automatically and update alert status in Autoheal.

Troubleshooting

401 Unauthorized
  • Verify the API token is correct and hasn't expired
  • Check that the service account hasn't been disabled
  • Ensure the token was copied completely
Connection Refused (Self-Hosted)
  • Verify the Grafana URL is correct
  • Check firewall rules allow access from Autoheal
  • Ensure Grafana is running and accessible
No Dashboards Found
  • Verify the service account has Viewer permissions
  • Check folder permissions for dashboards
Webhook Alerts Not Appearing in Autoheal
  • Verify the webhook URL in Grafana matches the URL shown in Autoheal
  • Check that the contact point is assigned to a notification policy
  • Ensure the alert rule is firing (check Alerting → Alert rules in Grafana)
  • Verify the webhook is enabled in the Autoheal integration settings
Webhook Returns 401 Unauthorized
  • If you configured a Webhook Signing Secret in Autoheal, ensure the same token is set in Grafana's Contact Point under Authorization Header - Credentials with Scheme set to Bearer
  • If you don't want auth header verification, remove the Webhook Signing Secret from the Alert Source tab in Autoheal
404 Errors on Prometheus Queries

If you receive 404 errors specifically on Prometheus queries:

  1. The agent automatically handles version-specific API formats
  2. The issue may be with datasource configuration or permissions
  3. Verify the datasource UID is correct using the "List data sources" query
  4. Check that the service account has access to the Prometheus datasource

Note: Loki and VictoriaLogs queries use a different endpoint format and typically don't have this issue.