---
title: "Query data | Grafana Cloud documentation"
description: "Use Grafana Assistant to write, explain, and optimize queries for Prometheus, Loki, Tempo, SQL databases, CloudWatch, Elasticsearch, and other supported data sources."
---

# 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                                            |
| Pyroscope (Grafana Cloud Profiles) | FlameQL                                            |
| Graphite                           | Graphite render API targets                        |
| InfluxDB                           | SQL (InfluxDB 3.x)                                 |
| k6 Cloud                           | k6 Cloud API                                       |
| PostgreSQL                         | SQL                                                |
| MySQL                              | SQL                                                |
| MSSQL                              | SQL                                                |
| ClickHouse                         | 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     |
| Elasticsearch                      | Lucene, aggregations                               |
| Honeycomb                          | Aggregation queries, SLOs, breakdowns              |
| Synthetic Monitoring               | Probes, checks, reachability, latency, error rates |
| MongoDB                            | NoSQL                                              |
| Oracle                             | SQL                                                |
| Dynatrace                          | Metrics, DQL (Grail), USQL                         |

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

## 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.

### Graphite

> 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.

### SQL databases

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

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

> Note
> 
> SQL Table Discovery is currently in [public preview](/docs/release-life-cycle/). Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.

### Cube

> 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.

### 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”.

### 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.

## 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.
- **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.”

## 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/machine-learning/assistant/guides/navigation) with the Assistant.
- Use your queries to [build dashboards](/docs/grafana-cloud/machine-learning/assistant/guides/dashboarding).
