Build Your Own Dashboard
Your readings live in one table per crate, and Grafana reads it with SQL. If you can write a SELECT, you can build any panel you like.
Not sure how to write the query? Ask the AI analyst. Every answer shows the SQL it ran, and you can paste it into a panel.
The table
Every crate has a table called readings.
| Column | What it holds |
|---|---|
time | When the reading was taken (UTC) |
device | The device |
metric | The metric |
value | The number |
The database is TimescaleDB (PostgreSQL), so functions like time_bucket, first and last work.
Make a panel
In Grafana, open Dashboards, then New, then New dashboard, and add a visualization.
Choose the crate's data source, named Crate - crate_….
Switch the query editor to Code and paste a query, like the ones below.
Save the dashboard.
Example queries
One metric over time
SELECT time, device, value
FROM readings
WHERE $__timeFilter(time)
AND metric = 'temperature'
ORDER BY time;
Averages per 5 minutes
SELECT time_bucket('5 minutes', time) AS time, device, AVG(value) AS temperature
FROM readings
WHERE $__timeFilter(time)
AND metric = 'temperature'
GROUP BY 1, device
ORDER BY 1;
Latest value from each device
SELECT device, last(value, time) AS battery
FROM readings
WHERE $__timeFilter(time)
AND metric = 'battery'
GROUP BY device;
$__timeFilter(time) limits the query to the time range picked at the top of the dashboard.
Dropdowns for devices and metrics
Add dashboard variables so viewers can pick a device or a metric:
| Variable | Type | Query |
|---|---|---|
device | Query | SELECT DISTINCT device FROM readings ORDER BY 1 |
metric | Query | SELECT DISTINCT metric FROM readings ORDER BY 1 |
Turn on Multi-value and Include All option, then use them in a query:
SELECT time, device, metric, value
FROM readings
WHERE $__timeFilter(time)
AND device IN (${device:sqlstring})
AND metric IN (${metric:sqlstring})
ORDER BY time;