Course contentsShow
← Cloud and Infrastructure
Lesson 1997 of 2,98942. Observability - MetricsFree lesson

Query Builder and Query Editor

Learn how to build queries using Grafana's query builder and write custom queries for different data sources.

Query Builder and Query Editor

You'll learn how to construct metrics queries in Grafana using both the visual query builder and the flexible query editor to pull exactly the data you need from your sources.

Understanding the Two Modes

Grafana gives you two ways to ask questions of your data. Think of the query builder as a form with dropdown menus—you click through options to build your query visually. The query editor is like typing free-form text—you write queries directly in the data source's native language (like PromQL for Prometheus).

The Query Builder

The query builder is your starting point. When you add a panel, Grafana presents options specific to your data source:

  • Select your metric from a dropdown
  • Choose labels to filter by
  • Pick aggregation operators like sum or avg
  • Define time ranges visually

For Prometheus, you might select a metric like http_requests_total, filter by method="GET", and apply rate() to see requests per second—all through clicks.

The Query Editor

For advanced users or complex queries, switch to the query editor (usually a button labeled "Code" or "Edit"). Here you write queries directly:

rate(http_requests_total{method="GET"}[5m])

This gives you full control over functions, subqueries, and expressions that might not exist in the builder. You can use everything you've learned about instant vectors, range vectors, and aggregation operators.

When to Use Each

Use the builder when exploring metrics or building simple visualizations. Switch to the editor when you need histogram quantiles, binary operators, or complex vector matching that requires precise syntax.

Key Takeaway: Grafana's query builder provides a user-friendly interface for constructing basic queries, while the query editor unlocks the full power of your data source's query language for advanced analysis.