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

# Grafana source

> Connect Grafana to Chartcastr and pulse any PromQL, SQL, or Loki metric to Slack or email — line or bar chart, with optional split Y-axis.

## Overview

Use Grafana as a data source for Chartcastr. Connect your Grafana host (self-hosted or Grafana Cloud) with a service-account token and Chartcastr will execute queries against your existing datasources — Prometheus, Loki, MySQL, Postgres, InfluxDB, and more — and chart the result.

Each Chartcastr source can pulse **up to two metrics** rendered as a line or bar chart. When two metrics have very different scales (say request rate at 5,000/s and error percentage at 0–5%), flip on the **split Y-axis** option to keep both legible.

<Note>
  Grafana metrics are user-defined — there is no preset metric list like Plausible or PostHog. You supply the query expression that Grafana itself would run.
</Note>

## Setup

<Steps>
  <Step title="Create a service account">
    <Tabs>
      <Tab title="Grafana Cloud">
        In your Grafana Cloud stack, go to **Administration → Users and access → Service accounts**. You can find it quickly by pressing `Cmd+K` (or `Ctrl+K`) and searching for "service".

        <Frame caption="Use the command palette to find Service accounts quickly">
          <img src="https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=0f989e973511a05275cd131a1b15cdc1" alt="Grafana command palette with 'service' typed, showing Service accounts result under Administration > Users and access" data-og-width="549" width="549" data-og-height="142" height="142" data-path="images/integrations/sources/grafana/find-service-accounts.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=280&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=5c1a7465c50e96240fbe16dc3be189c9 280w, https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=560&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=8f156be06f256c753d844b94b26060f9 560w, https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=840&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=821c3cbc99180eceff4aff20d480379b 840w, https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=1100&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=aaed062ca5b9b4671605aca5fcfab5fe 1100w, https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=1650&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=033a230f620d68feaf92fffbd0f5724a 1650w, https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/find-service-accounts.png?w=2500&fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=c5a084e3716e2458a93bfb1c7d2037d3 2500w" />
        </Frame>

        Click **Add service account**, give it a name (e.g. `chartcastr-integration`), and set the role to **Viewer**. Viewer access is all Chartcastr needs — it only reads metric data.

        <Frame caption="Create a new service account with the Viewer role">
          <img src="https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/create-service-account.png?fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=5449cb3837ac5b5f6d40ce384e3973a8" alt="Grafana Create service account screen with Display name field and Role set to Viewer" width="777" height="394" data-path="images/integrations/sources/grafana/create-service-account.png" />
        </Frame>
      </Tab>

      <Tab title="Self-hosted Grafana">
        In your Grafana instance, go to **Administration → Users and access → Service accounts**. You can find it quickly by pressing `Cmd+K` (or `Ctrl+K`) and searching for "service".

        Click **Add service account**, give it a name (e.g. `chartcastr-integration`), and set the role to **Viewer**. Viewer access is all Chartcastr needs — it only reads metric data.

        <Note>
          Service accounts require **Grafana 8.5 or later**. If you're on an older version, upgrade before proceeding or use a basic-auth API key instead (contact support).
        </Note>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Generate a service account token">
    Click into the service account you just created, then click **Add service account token**.

    <Frame caption="Add a token to the service account">
      <img src="https://mintcdn.com/chartcastr/D96dMZVhEfYKcoA8/images/integrations/sources/grafana/add-service-account-token.png?fit=max&auto=format&n=D96dMZVhEfYKcoA8&q=85&s=c233ac73c0fffbacb147282f70bd93a5" alt="Grafana Add service account token dialog showing display name and expiration options" width="1032" height="447" data-path="images/integrations/sources/grafana/add-service-account-token.png" />
    </Frame>

    Give the token a display name and set an **expiration date**. We recommend **1 year** — long enough to avoid frequent rotation, short enough to limit exposure if the token is ever compromised. Copy the generated `glsa_...` token; you won't be able to view it again.

    <Warning>
      Store the token somewhere safe before closing the dialog. Grafana only shows it once.
    </Warning>
  </Step>

  <Step title="Connect in Chartcastr">
    In Chartcastr, go to **New Source** and select **Grafana**. Enter:

    * **Grafana host** — the full URL of your Grafana instance

    <Tabs>
      <Tab title="Grafana Cloud">
        Your Grafana Cloud URL looks like `https://yourorg.grafana.net`. Find it in the Grafana Cloud portal under your stack details.
      </Tab>

      <Tab title="Self-hosted Grafana">
        Use the URL your team browses to — e.g. `https://grafana.example.com` or `http://localhost:3000` for local setups. Make sure the host is reachable from the internet (Chartcastr's servers need to reach it).
      </Tab>
    </Tabs>

    * **Service account token** — the `glsa_...` token from the previous step

    Click **Test & Connect** to validate the connection.
  </Step>

  <Step title="Pick a datasource">
    Chartcastr loads the list of datasources available to your service account. Pick the one your metric lives in (Prometheus, Loki, your SQL database, etc.).
  </Step>

  <Step title="Enter a query">
    Paste the query expression for your metric — PromQL for Prometheus, LogQL for Loki, raw SQL for SQL datasources. Add an optional label to use in the legend.

    Example PromQL:

    ```promql theme={null}
    sum(rate(http_requests_total{job="api"}[5m]))
    ```

    Example LogQL:

    ```logql theme={null}
    sum(count_over_time({app="api"} |= "ERROR"[5m]))
    ```
  </Step>

  <Step title="(Optional) Add a second metric">
    Click **Add second metric** to overlay a second series on the same chart. If the two metrics have very different ranges, enable **Split Y-axis** so each gets its own scale.
  </Step>

  <Step title="Pick chart type + window">
    Choose **Line** or **Bar**, then pick how far back to look (1 hour, 6 hours, 24 hours, 7 days, or 30 days).
  </Step>

  <Step title="Preview and save">
    Click **Preview chart** to see what the rendered chart looks like with live data. Save the source, then create a connection to your Slack channel or email destination.
  </Step>
</Steps>

## Supported datasource types

Chartcastr's Grafana integration runs queries via Grafana's `/api/ds/query` endpoint, which supports any datasource installed in your Grafana — including:

* **Prometheus** (PromQL)
* **Loki** (LogQL)
* **MySQL / Postgres / MSSQL** (SQL)
* **InfluxDB** (InfluxQL / Flux)
* **ClickHouse**
* Any community datasource plugin that accepts a `query` field

## Notes

* **Only integer metrics**: values are rounded to integers. This is fine for counts and rates but means decimal-precision metrics (e.g. 0.823 ratios) will lose precision.
* **Time-series only**: queries must return a time-series shape. Single-value (instant) queries are not yet supported.
* **Service-account token is encrypted**: stored AES-256-GCM-encrypted at rest, never exposed back to the client.
* **Self-hosted reachability**: Chartcastr's servers must be able to reach your Grafana host over HTTPS. If your Grafana is behind a private network or VPN, use Grafana Cloud or expose it via a reverse proxy with a valid TLS certificate.
