Grafana: Query
grafana_queryRun raw queries against any Grafana datasource through /api/ds/query, including SQL, Elasticsearch, Tempo, and CloudWatch, or evaluate server-side expression queries over other results.
Instructions
Run raw queries against any datasource through /api/ds/query — for datasources with no dedicated tool (SQL, Elasticsearch, Tempo, CloudWatch…), or for server-side expressions over other queries ({"datasource": "__expr__", "type": "math", "expression": "$A / $B"}). Each query is the target object as it appears in a panel's JSON (grafana_get_dashboard view=panel shows one). Prefer grafana_query_prometheus / grafana_query_loki for those two, and grafana_run_panel_query to reproduce a panel. Dashboard variables are NOT filled in here.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | Range end: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now. | |
| from | No | Range start: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now-1h. | |
| sort | No | Order of time series, applied before `limit` cuts: labels keeps the datasource's order; max/avg/last rank highest first, so a cut keeps the biggest. | labels |
| view | No | For time series. values: stats (min/max/avg/last) plus one value per step on a shared grid given by start and step, null where there was no sample. stats: the stats only, about a tenth of the size — use it to survey many series before reading a few. | values |
| limit | No | Maximum series, log lines or table rows per query (1-5000). Defaults to 100. | |
| points | No | Target points per series (2-1000), from which the step is picked. Defaults to 60; a dashboard in a browser asks for ~1000, which is rarely worth the tokens. | |
| queries | Yes | Query objects, e.g. [{"refId": "A", "rawSql": "SELECT 1", "format": "table"}]. A query may carry its own "datasource" (uid string, or {"uid": ...}); refId defaults to A, B, C…. | |
| precision | No | Significant digits to round fractional values to (whole numbers are never rounded). Defaults to 4; 0 returns the exact value. | |
| datasource | No | Datasource uid or name, e.g. "prometheus" or "Loki". Defaults to the default datasource, for queries that name none. grafana_list_datasources lists them. | |
| max_line_chars | No | Cut each log line at this many characters (50-20000). Defaults to 1000. |