Grafana: Query Prometheus
grafana_query_prometheusEvaluate PromQL expressions against a Prometheus datasource to retrieve instant values or range trends, with per-series min/max/avg/last stats for outlier detection and aggregation.
Instructions
Evaluate PromQL through a Prometheus datasource. mode=instant (default) gives the value at one time — the right mode for almost every question, with any window written into the expression (increase(x[24h])). mode=range gives the shape over time on a step grid with min/max/avg/last per series; use view=stats with sort=max to find outliers among many series. Labels shared by every series come back once as common_labels. Aggregate in the expression (sum by, topk) rather than fetching raw series.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | Range end for mode=range: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now. | |
| expr | Yes | A PromQL expression, e.g. `sum by (namespace) (rate(container_cpu_usage_seconds_total[5m]))`. $__interval, $__rate_interval and $__range are filled in by Grafana. | |
| mode | No | instant (default) or range. | instant |
| 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 |
| step | No | Resolution, as a duration (30s, 5m, 1h). Defaults to a round step giving `points` points. Grafana never goes below the datasource's scrape interval. | |
| time | No | Evaluation time for mode=instant: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now. | |
| 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 (1-2000). Defaults to 100. To see the largest, write topk() into the query. | |
| start | No | Range start for mode=range: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now-1h. | |
| 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. | |
| 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 Prometheus datasource. grafana_list_datasources lists them. |