Skip to main content

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.

tip

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.

ColumnWhat it holds
timeWhen the reading was taken (UTC)
deviceThe device
metricThe metric
valueThe number

The database is TimescaleDB (PostgreSQL), so functions like time_bucket, first and last work.


Make a panel​

Step 1: New dashboard

In Grafana, open Dashboards, then New, then New dashboard, and add a visualization.

Step 2: Pick the crate

Choose the crate's data source, named Crate - crate_….

Step 3: Write the query

Switch the query editor to Code and paste a query, like the ones below.

Step 4: Save

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.


Add dashboard variables so viewers can pick a device or a metric:

VariableTypeQuery
deviceQuerySELECT DISTINCT device FROM readings ORDER BY 1
metricQuerySELECT 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;