Building a Time-Series Panel

Introduction: From Connection to Visualization

In the previous lesson, you successfully connected Grafana to your PostgreSQL database and verified that the connection was working. That was an important first step, but now comes the exciting part — actually using that connection to create visualizations. In this lesson, you'll move from simply being connected to actively querying your data and seeing it displayed on a chart.

You might be thinking, "I know SQL, so writing queries in Grafana should be straightforward, right?" Well, almost. Grafana does use SQL, but it adds some special functionality on top of it. When you write a query for a Grafana panel, you're not just retrieving data — you're retrieving data in a specific format that Grafana can transform into beautiful, interactive charts. Think of it as SQL with superpowers that connect directly to Grafana's time range controls and visualization engine.

By the end of this lesson, you'll have written your first time-series query that displays CPU usage across different hosts. You'll understand the specific structure Grafana needs and learn to use special macros that make your queries work seamlessly with Grafana's interface. This pattern you learn here will become the foundation for every time-series panel you create going forward.

Getting to the Query Editor (Explore)

Note: From this unit forward, anonymous mode is enabled in all practice exercises so you won't need to sign in each time. This is for lab convenience only—never use anonymous access in production. In real environments, always require proper authentication and restrict permissions according to best practices. For more information, see the Grafana authentication documentation.

Before you can write any queries, you need to know where to write them. Grafana provides a dedicated space called the Explore section specifically for testing and developing queries before adding them to dashboards. You can find Explore in the left sidebar — it looks like a compass icon. When you click on it, Grafana opens a query workspace where you can experiment with data retrieval and visualization.

Once you're in Explore, notice that your configured Postgres data source — in this lab environment, it's named Postgres Local — is already selected at the top. When you open Explore with this data source, Grafana helpfully displays a list of available tables in your database. You can see tables like log_events, metrics_cpu, metrics_disk, and others that contain your demo metrics data. This gives you a quick reference of what data is available to query.

What you're looking at right now is the Builder tab — Grafana's visual, form-based interface for constructing queries. You can select tables and columns from dropdowns and build queries without writing SQL directly. While the Builder can be useful for simple queries, we're going to work with the Code tab instead, which gives you much more freedom and control.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal