
Consult the macros section of the documentation for your database data source. If you’re using a SQL database other than MySQL, most of the same macros are supported for others like PostgreSQL and Oracle. Let’s start with a finished SQL query using all the appropriate macros, and then unpack what it’s doing and how it works. And in the context of a Grafana dashboard, you need to take into account things like the time window the dashboard is covering (e.g., whether it’s the last five minutes or past two years). Writing SQL queries can be repetitive, particularly if you need to write many queries for different panels in a dashboard. Instead, we can aggregate those payments into blocks of one hour at a time, which will still give us sufficient data for our dashboard. You can follow our general example using any SQL dataset of your own, so long as it has some kind of numeric or metric field (like amount) and a datetime field (like payment_date).įor the purposes of our example, we might not want to see every payment at every moment - it’s just too granular.

In general, the time series panel will look for columns that are of date/time types, or columns that look like UNIX times (seconds since the epoch). The thing to note about this data is that it has an amount field, which is the metric we want to see in our time series, and it has a payment_date, which is a datetime field we’ll want to use. In the below screenshot, we’re simply running SELECT * FROM sakila.payment. Let’s start with simple payment data from a video service, stored in MySQL. You can inspect it yourself on Grafana Play, a sample Grafana instance where we share sample dashboards and help teach people how they work.

We will be building the following finished visualization. In the process, you’ll learn about what kind of data the time series panel can visualize, and how to use SQL macros in Grafana. In this article, we’re going to show you how to visualize any time series from any SQL database in Grafana using the time series visualization. Often this data can be used to enhance observability dashboards, or keep track of important application factors, like how many users have signed up for a service.


Relational databases like MySQL, PostgreSQL, Oracle, and others have a wealth of time series data locked inside of them.
