Grafana: How to chart multiple time series from a single SQL query?

Hello,

I can’t figure out how to “split” the data returned from a single SQL query:

| timestamp   | server | temperature |
--------------------------------------
| 2021-08-01 |    1    |    10       |
| 2021-08-01 |    2    |    21       |
| 2021-08-01 |    3    |    3        |
| 2021-08-02 |    1    |    11       |
| 2021-08-02 |    2    |    20       |
| 2021-08-02 |    3    |    4        |

into multiple time-series, and plot them on the same chart (see below):

image

Here is my SQL query:

SELECT
  $__time("timestamp"),
  "temperature"
FROM "temperature"
WHERE $__timeFilter("timestamp")
GROUP BY server, timestamp
ORDER BY timestamp ASC

Currently, only ONE time-series is being plotted on the time-series chart.

I expected Grafana to plot one time-series per server ID.

Any help would be much appreciated!

Thank you

  • grafana version: v8.2.0-beta2
  • datasource: Postgresql

Ok, it seems like just adding “server” to the SELECT statement suffice for grafana to understand that time-series should be split by server ID:

SELECT
  $__time("timestamp"),
  "temperature",
  "server"  <--- add here
FROM "temperature"
WHERE $__timeFilter("timestamp")
--- GROUP BY server, timestamp    <---- remove that
ORDER BY timestamp ASC

This topic was automatically closed after 365 days. New replies are no longer allowed.