# Grafana: Query Metrics

Runs a PromQL query against a Grafana Prometheus datasource, either as an instant evaluation or a range query over a time window.


> **Availability:** See the [Incident Workflow Actions Overview table](/workflow-actions) for the plans this workflow is available on.

## Description

Execute a PromQL query against a Grafana Prometheus datasource, either as an instant evaluation or as a range query across a time window. This action enables automated metrics analysis during incident response, allowing teams to programmatically retrieve diagnostic data without manually searching Grafana dashboards.

## Instructions

1. If you have not done so, follow the instructions to [Create an Incident Workflow](/ai-automation/automation/incident-workflows#create-an-incident-workflow).
2. When the instructions prompt you to [add actions](/ai-automation/automation/incident-workflows#add-actions), select **this action**.
3. Enter the following **Inputs** and click **Save**.
4. Continue following instructions to **Publish** the Workflow.
5. When the action runs, you will see the **Outputs** listed below.

## Inputs

> **Field References:** Fields with the **\{+\}** icon accept [Field References](/ai-automation/automation/incident-workflows#field-references), which can be useful for referencing incident data or outputs created in prior workflow steps. To add Field References, click **\{+\}**, or enter `{{`, and select relevant fields. Refer to the [Field References](/ai-automation/automation/incident-workflows#field-references) article for more information.

| Name                             | Description                                                                                                                 |
| :------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- |
| **Connection Input**             | The Grafana Connection to use for the query.                                                                                |
| **Datasource**                   | The Prometheus datasource UID to query for metrics.                                                                         |
| **Query**                        | The PromQL query expression. For example, `rate(http_requests_total[5m])` or `sum by (pod) (container_memory_usage_bytes)`. |
| **Query Type**<br />_(Optional)_ | Instant evaluates the query at the End Time; Range returns a time series across the window.                                 |
| **Start Time**<br />_(Optional)_ | The start time of the query window, used for Range queries.                                                                 |
| **End Time**<br />_(Optional)_   | The end time of the query window, also the evaluation time for Instant queries.                                             |
| **Step**<br />_(Optional)_       | Resolution step for Range queries, for example, `15s`, `1m`, or `5m`. Ignored for Instant queries.                          |

## Outputs

| Name                  | Description                                                                            |
| :-------------------- | :------------------------------------------------------------------------------------- |
| **Results**           | Array of time series, each with labels and an array of \{timestamp, value\} data points. |
| **Series Count**      | Total number of time series returned.                                                  |
| **Total Data Points** | Total number of data points across all series.                                         |
| **Query Used**        | The PromQL query string that was sent to Grafana.                                      |
| **Query Type Used**   | `instant` or `range`.                                                                  |
| **Time Range Start**  | The start time used for the query.                                                     |
| **Time Range End**    | The end time used for the query.                                                       |
| **Search Duration**   | API response time in milliseconds.                                                     |
| **Result**            | Value that shows if the action was successful or not. Either `Success` or `Failed`.    |
| **Result Summary**    | Brief description of what the action did or if it failed.                              |
| **Error**             | Brief description that is populated if the action failed.                              |

> **Instant vs. Range queries:** Instant evaluates the query at the End Time and returns a single value per series. Range returns a time series across the window defined by Start Time and End Time, resolved at the interval set by Step.

<br />
