---
title: "Query data | Grafana Cloud documentation"
description: "Use Grafana Assistant to write, explain, and optimize queries, discover Tempo trace comparison candidates, and investigate data from Prometheus, Loki, SQL databases, and other supported data sources."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Query data

Grafana Assistant can write, explain, and optimize queries across your observability stack. Describe what you need in natural language, and the Assistant generates valid syntax and visualizes the results.

## Before you begin

Ensure the data sources you want to query are configured in your Grafana instance.

> Tip
> 
> Use the `@` symbol to mention a specific data source in your prompt (for example, `@prometheus-ds`) so the Assistant queries the correct one.

## Supported data sources

Expand table

| Data source                        | Supported queries                                             |
|------------------------------------|---------------------------------------------------------------|
| Prometheus                         | PromQL                                                        |
| Loki                               | LogQL                                                         |
| Tempo                              | TraceQL, experimental baseline discovery and trace comparison |
| Pyroscope (Grafana Cloud Profiles) | FlameQL                                                       |
| Graphite                           | Graphite target expressions                                   |
| InfluxDB                           | SQL (InfluxDB 3.x), InfluxQL, Flux                            |
| k6 Cloud                           | k6 Cloud API                                                  |
| PostgreSQL                         | SQL                                                           |
| MySQL                              | SQL                                                           |
| MSSQL                              | SQL                                                           |
| ClickHouse                         | SQL                                                           |
| Hydrolix                           | Read-only ClickHouse-compatible SQL                           |
| BigQuery                           | SQL                                                           |
| Athena                             | SQL                                                           |
| Snowflake                          | SQL                                                           |
| Databricks                         | SQL                                                           |
| Cube                               | Semantic layer (measures, dimensions, filters)                |
| Infinity                           | JSON API using URL, `jq` transforms                           |
| CloudWatch                         | MetricStat, Metric Insights SQL, Logs Insights                |
| Azure Monitor                      | Metrics, Log Analytics (KQL)                                  |
| Elasticsearch                      | Lucene, aggregations                                          |
| Honeycomb                          | Aggregation queries, SLOs, breakdowns                         |
| Synthetic Monitoring               | Probes, checks, reachability, latency, error rates            |
| MongoDB                            | NoSQL                                                         |
| New Relic                          | NRQL, event types, attributes                                 |
| Splunk                             | SPL queries, indexes, sourcetypes, fields                     |
| Oracle                             | SQL                                                           |
| Datadog                            | Metrics, logs                                                 |
| Dynatrace                          | Metrics, DQL (Grail), USQL                                    |
| Jira                               | JQL queries, projects, issues                                 |
| Jaeger                             | Trace search, trace by ID, service dependencies               |
| Zabbix                             | Host groups, hosts, items, problems, metrics                  |
| AppDynamics                        | Metrics, analytics                                            |
| TestData                           | Synthetic scenarios and generated data frames                 |

For every data source the workflow is the same: describe what you want, refine the results, and optionally visualize them on a dashboard.

## Use data sources in investigations

Investigations search metrics, logs, traces, and profiles by default. Other configured data sources are available, but connecting one doesn’t cause every investigation to search it automatically.

To use another data source, add a [rule](/docs/grafana-cloud/platform/grafana-assistant/configure/rules) or [skill](/docs/grafana-cloud/platform/grafana-assistant/platform/skills) that tells the Assistant when it’s relevant and what evidence to retrieve.

## Example prompts

### Prometheus

> Create a PromQL query in @prometheus-ds that shows p95 latency for checkout\_service over the last hour.

> Group by region and sort by highest error rate.

### Loki

> Find logs from @loki-logs where job=“checkout” and level=“error” in the last 15 minutes.

> Parse the JSON payload and show the top five error codes.

### Tempo

> Query @tempo-traces for traces longer than 2 seconds.

> Show the slowest spans and include their service names.

When experimental trace comparison is available, you can ask the Assistant to find comparison candidates from a single incident trace. It matches the root service and operation and, by default, up to three downstream services. Candidate searches return five traces by default, with a maximum of 20, and preserve Tempo’s search order rather than ranking results.

The default search window extends 30 minutes before and after the incident trace. Specify a pre-incident window when you want a historical comparison. The candidate search window is independent of the time range used to look up the incident trace.

> Find baseline candidates for trace `<TRACE_ID>` in @tempo-traces, using traces from the 30 minutes before the incident.

> Compare the selected candidate with my incident trace. Explain the differences and any limits on comparability.

Candidates have non-error root spans, but they aren’t verified healthy. They can still be slow, contain downstream errors, or represent different workloads. The Assistant reports partial-trace warnings, missing statistics, and truncated results. If no candidates match, you can refine the search window or explicitly ask to match the same operation without requiring the same downstream services.

### Pyroscope

> Analyze the CPU flame graph for checkout\_service in @profiles over the last hour.

> Analyze the profile linked to span ID `a43b531bf8ca2e89` in @profiles and identify the most expensive call path.

### Jaeger

> What services are available in @jaeger-ds?

> Search for traces from the frontend service in @jaeger-ds with errors in the last hour.

> Analyze trace abc123def456 from @jaeger-ds and identify performance bottlenecks.

> Show the service dependency graph from @jaeger-ds.

### Graphite

Graphite queries and metric discovery run through the Grafana datasource plugin, using its configured authentication and query limits.

> Show the metrics tree under `servers.web.*` in @graphite-ds.

> Query @graphite-ds for the average CPU load across all web servers over the last 6 hours.

### InfluxDB

The Assistant detects whether an InfluxDB data source uses InfluxQL or Flux and writes queries in the matching language. InfluxDB 3.x data sources in SQL mode use the SQL prompts instead.

> What measurements are available in @influxdb-ds?

> Show the field keys and tag keys for the `cpu_usage` measurement in @influxdb-ds.

> Query @influxdb-ds for the maximum `usage_idle` from `cpu_usage` grouped by host over the last hour.

> List the buckets in @influxdb-flux-ds, then show the maximum CPU idle from `cpu_usage` over the last hour in Flux.

### TestData

> What executable scenarios are available in @testdata-ds?

> Run the CSV Metric Values scenario in @testdata-ds with the values `1,20,90,30,5,0`.

> Run 10 different executable scenarios against @testdata-ds and summarize the result shape of each.

### SQL databases

Use SQL table discovery when you want Assistant to inspect schemas before it writes a query. For BigQuery data sources, Assistant also shows table row counts and the last modified date when it discovers tables. This helps you choose live tables before you query a large dataset.

> Find tables in @orders-database that track checkout failures.

> Query for failed checkouts per minute grouped by payment\_provider.

> In @analytics-bigquery, show the BigQuery tables with recent updates for checkout reporting.

> In @analytics-bigquery, find tables with row counts that look useful for payment failure analysis.

SQL Table Discovery lets Assistant inspect tables and columns before it writes a SQL query. For supported sources, Assistant can also discover table parameter values, such as available projects or indexes, and column values for building narrower `WHERE` filters.

For BigQuery data sources, Assistant can use table discovery to show table row counts and the last modified date before it writes SQL.

For ClickHouse data sources, Assistant can inspect tables named as `database.table` and discover column values over a selected time range before querying large tables. For Elasticsearch data sources, Assistant can discover indexes, aliases, data streams, and fields before it queries documents.

For Hydrolix data sources, Assistant discovers tables as `project.table` and runs read-only `SELECT` queries. Include a time range when querying event data so Hydrolix can limit the object-storage scan.

> Find Hydrolix tables in @hydrolix-logs that contain HTTP status and request duration fields.

> In @hydrolix-logs, show the p95 request duration by service over the selected time range.

### Cube

Query Cube measures and dimensions in Assistant chat and investigations. Query results can be referenced as panels in chat and investigation Sources.

> What measures and dimensions are available in @cube-ds?

> Query @cube-ds for total revenue by product category over the last 30 days, filtered to the US region.

### CloudWatch

> What CloudWatch namespaces are available in @cloudwatch-ds?

> Show the average CPUUtilization for EC2 instances in @cloudwatch-ds over the last hour.

> Find error logs in the /aws/lambda/my-function log group from the last 15 minutes.

> Show recent alarm state changes for alarms with the prefix “prod-high-cpu” in @cloudwatch-ds.

### Azure Monitor

> What subscriptions are available in @azure-monitor-ds?

> Show available metrics for my virtual machine in @azure-monitor-ds.

> Query @azure-monitor-ds for Percentage CPU on my-vm averaged over the last hour.

> Run a KQL query against @azure-monitor-ds: AzureActivity | where Level == “Error” | take 50.

### Elasticsearch

> What fields are available in @search-logs?

> Find error logs in @search-logs where `service.name` is checkout in the last 15 minutes.

> Show the average `duration_ms` grouped by `service.name` from @search-logs over the last hour.

### Honeycomb

> What datasets are available in @honeycomb-ds?

> Show p99 latency by service and route from the `production` dataset in @honeycomb-ds over the last hour.

> Show error counts broken down by status code and service in @honeycomb-ds.

### Infinity (external APIs)

> Query the API at [https://api.example.com/metrics](https://api.example.com/metrics) and show me the results.

> Query [https://api.example.com/data](https://api.example.com/data) and extract only the items where status is “active”.

The Infinity `allowedHosts` setting controls which URLs the Assistant can reach. With it configured, matching URLs are queried automatically. Without it, the Assistant prompts you to approve each request. For more information, refer to the [Infinity allowed hosts documentation](/docs/plugins/yesoreyeram-infinity-datasource/latest/references/url/#allowed-hosts).

### Synthetic Monitoring

> List all probes available in @synthetic-monitoring.

> Show the latency and success rate for the checkout health check over the last hour.

### MongoDB

> What collections are available in @mongodb-ds?

> Show the schema for the `orders` collection in @mongodb-ds.

> Query @mongodb-ds for failed orders in the `orders` collection over the last hour, grouped by payment\_provider and sorted by count.

> Filter to only include failures where the error code is “INSUFFICIENT\_FUNDS”.

### AppDynamics

> What applications are monitored in @appdynamics-ds?

> Show the metric tree for my application in @appdynamics-ds.

> Query @appdynamics-ds for Calls per Minute over the last hour.

> Run an analytics query against @appdynamics-ds: SELECT count(\*) FROM transactions.

### New Relic

> What event types are available in @newrelic-ds?

> Show attributes for the Transaction event type in @newrelic-ds.

> Query @newrelic-ds for average response time from Transaction events over the last hour.

> Show error count by appName from TransactionError events in @newrelic-ds over the last 30 minutes.

### Datadog

> Show available metrics matching “system.cpu” in @datadog-ds.

> Query @datadog-ds for average CPU usage grouped by host over the last hour.

> Search logs in @datadog-ds for errors in the web service over the last 30 minutes.

### Dynatrace

> Show built in metrics for cpu and memory in @dynatrace-ds.

> Query @dynatrace-ds for cpu and memory utilization over the last 12 hours.

> Show average CPU usage for all hosts in @dynatrace-ds over the last hour.

### Oracle

> What schemas and tables are available in @oracle-ds?

> Show the schema for the `HR.EMPLOYEES` table in @oracle-ds.

> Query @oracle-ds for total order revenue grouped by category over the last 7 days.

> Show failed orders from `TESTDATA.ORDERS` in @oracle-ds over the last 24 hours, grouped by status.

### Jira

> What projects are available in @jira-ds?

> Show open bugs in the PLATFORM project from @jira-ds, sorted by priority.

> Query @jira-ds for issues assigned to me that are in progress.

> Show a breakdown of unresolved issues by status and assignee in the OPS project from @jira-ds.

### Zabbix

> What host groups are available in @zabbix-ds?

> List hosts in the “Linux servers” group in @zabbix-ds.

> Show available CPU and memory metrics for the Zabbix server host in @zabbix-ds.

> Are there any active problems with severity “High” or above in @zabbix-ds?

> Query @zabbix-ds for CPU utilization across all Linux servers over the last hour.

### Splunk

> What indexes are available in @splunk-ds?

> Show the sourcetypes in the “main” index from @splunk-ds.

> Search @splunk-ds for error logs in the “\_internal” index over the last hour.

> Query @splunk-ds for a timechart of events by sourcetype in the “main” index over the last 24 hours.

## Tips for better results

- **Be specific about time ranges.** Prompts like “last 15 minutes” or “over the past 24 hours” help the Assistant pick the right window and avoid scanning too much data.
- **Keep historical queries within supported windows.** Assistant chat and Workspace support absolute timestamps up to three years in the past for query tools.
- **Mention the data source by name.** Use the `@` prefix (for example, `@prometheus-prod`) when you have multiple data sources of the same type so the Assistant targets the correct one.
- **Start broad, then refine.** Ask for a general query first, then follow up with filters, groupings, or aggregations in subsequent messages.
- **Ask for explanations.** You can paste an existing query and ask “Explain this query” to understand what it does before modifying it.
- **Request alternatives.** Ask the Assistant to suggest different approaches, for example: “Is there a more efficient way to write this PromQL?”
- **Combine signals.** You can ask the Assistant to correlate across data sources in a single conversation, for example: “Show me error logs from Loki around the time latency spiked in Prometheus.”

## Watcher agents

Watcher agents can evaluate saved checks on these query types:

Expand table

| Data source      | Watcher query type  | Notes                                                                                                                                                                                                                                                                                                                                                           |
|------------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Prometheus       | `promql`            | Instant PromQL at each cadence.                                                                                                                                                                                                                                                                                                                                 |
| Loki             | `logql`             | Raw streams and LogQL metrics.                                                                                                                                                                                                                                                                                                                                  |
| Tempo            | `traceql_metrics`   | Whole-window TraceQL metrics (`rate`, quantiles). Feature-flagged.                                                                                                                                                                                                                                                                                              |
| Pyroscope        | `pyroscope_series`  | Whole-window `SelectSeries` for a CPU, wall-time, allocation, or retained-heap profile type plus a `service_name` selector, written as `<profile_type_id>{<selector>}`. Feature-flagged (`assistant.watcher-agents-pyroscope-series`). Flame graphs and `group_by` are not Watcher checks in v1.                                                                |
| CloudWatch       | `cloudwatch_metric` | Whole-window MetricStat checks with region, namespace, metric, statistic, and dimensions. Calibrate with `execute_metrics_window` over one cadence window; Sum and SampleCount thresholds are per minute. CloudWatch Logs, Metrics Insights SQL, and metric math are not Watcher checks in v1. Feature-flagged (`assistant.watcher-agents-cloudwatch-metrics`). |
| BigQuery         | `bigquery`          | Read-only Standard SQL.                                                                                                                                                                                                                                                                                                                                         |
| Infinity         | `infinity`          | One `GET` request to a JSON or XML endpoint, optionally shaped with a `jq` selector. The URL’s origin must be in the data source’s `allowedHosts`; Watchers never ask for approval. Numeric fields can carry thresholds, and other fields are read as context on every run.                                                                                     |
| Grafana Alerting | `alerts`            | Matcher-based firing-alert input.                                                                                                                                                                                                                                                                                                                               |

## Optimize existing queries

Paste any query and ask the Assistant to review it for performance or correctness.

> Review this PromQL query for performance: `sum(rate(http_requests_total[5m]))`

> Remove high-cardinality labels.

> Rewrite this LogQL query to use stream selectors instead of line filters for better performance.

## Next steps

- Learn how to [navigate Grafana](/docs/grafana-cloud/platform/grafana-assistant/guides/navigation) with the Assistant.
- Use your queries to [build dashboards](/docs/grafana-cloud/platform/grafana-assistant/guides/dashboarding).
