A query of your own that runs well over one day can hit Grafana’s time limit over two weeks and leave the panel empty. This page explains why and how to avoid it, including with the minute values from firmware 2.47.22. Which signal names exist and how to pick the machine is covered in IDEA-4S – signal names in the DataStore.
Build your own queries in a copy of the shipped dashboard (Save as copy / Als Kopie speichern), not in the original: a firmware update replaces the original.
1. How the measured values are stored
All measured values are in the table historicValues, one value per row:
| Column | Content |
|---|---|
machine_id | Number of the machine (table machines) |
signal_name | Signal name, e.g. VibVeloXDirection |
source_time_unix_nanos | Time of the measurement in nanoseconds since 1970, UTC, as an integer |
value | The value as JSON: a number or, for status signals, an object |
This means for every query:
(hv.value #>> '{}')::double precisiontakes the number out of the JSON.- The line
AND jsonb_typeof(hv.value) = 'number'always belongs in the query. Without it, the query fails as soon as a status object is selected.
The database stores each day (UTC) in its own day slice (historicValues_d20261112 and
so on). You still always query historicValues. If the time condition is on
source_time_unix_nanos itself, the database reads only the slices in the selected range.
2. Bound every query in time
A query without a time condition reads every day, which on a well-filled edge means many gigabytes. Always bound it, and do so on the column itself:
AND hv.source_time_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND hv.source_time_unix_nanos < $__unixEpochTo()::bigint * 1000000000
Not like this: to_timestamp(hv.source_time_unix_nanos / 1e9) > now() - interval '7 days'.
It selects the same rows, but the database has to convert every row first and cannot skip
any day slice.
The “latest value” for a tile needs a bound too. The shipped dashboard uses a 24-hour window:
SELECT
to_timestamp(hv.source_time_unix_nanos / 1e9) AS "time",
(hv.value #>> '{}')::double precision AS temperature_bearing_1
FROM "historicValues" hv
WHERE hv.machine_id = COALESCE(NULLIF('${machine}', '')::bigint,
(SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND hv.signal_name = 'TempBearing1'
AND hv.source_time_unix_nanos > (extract(epoch FROM now()) - 86400)::bigint * 1000000000
AND jsonb_typeof(hv.value) = 'number'
ORDER BY hv.source_time_unix_nanos DESC
LIMIT 1
If no value arrived in 24 hours, the tile stays empty. That is intended: an older value would show a state that no longer applies.
3. Downsample time series
A week-long time series of one IDEA-4S covers several million raw values. A panel cannot usefully draw more than about 1000 points. Let the database form time buckets and return one value per bucket:
SELECT
to_timestamp(bucket * $__interval_ms / 1000.0) AS "time",
avg(v) FILTER (WHERE signal_name = 'TempBearing1') AS bearing_1,
avg(v) FILTER (WHERE signal_name = 'TempBearing2') AS bearing_2
FROM (
SELECT
hv.source_time_unix_nanos / ($__interval_ms::bigint * 1000000) AS bucket,
hv.signal_name,
(hv.value #>> '{}')::double precision AS v
FROM "historicValues" hv
WHERE hv.machine_id = COALESCE(NULLIF('${machine}', '')::bigint,
(SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND hv.signal_name IN ('TempBearing1', 'TempBearing2')
AND hv.source_time_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND hv.source_time_unix_nanos < $__unixEpochTo()::bigint * 1000000000
AND jsonb_typeof(hv.value) = 'number'
) sub
GROUP BY bucket
ORDER BY bucket
What matters:
bucketis an integer computed from the nanosecond timestamp. Only the outer query creates the timestamp, once per bucket. Ato_timestamp(…)per raw value makes the same query three to five times slower.avg(v)for temperatures,max(v)for vibration velocities, so that peaks stay visible.- Under Query options, set Max data points = 1000. Grafana derives
$__interval_ms, the length of one bucket, from it. - Not
SELECT … ORDER BY timewithout downsampling: Grafana then receives every raw value and still draws only a fraction of them.
Even downsampled, this query reads every raw value in the range. For long ranges there are therefore the minute values (next section).
4. Minute values for long ranges
From firmware 2.47.22 (DataStore 5.139.2) the DataStore also summarises every signal that carries numbers per
minute, in the table historicValuesMinute:
| Column | Content |
|---|---|
machine_id | Number of the machine, as in historicValues |
source_name | Name of the data source the signal came from |
signal_name | Signal name, as in historicValues |
minute_unix_nanos | Start of the minute in nanoseconds since 1970, UTC |
value_min, value_max | Smallest and largest numeric value of the minute |
value_avg | Mean of the numeric values stored in the minute, not weighted by duration |
value_count | Number of numeric values in the minute |
value_invalid | Number of values that were not a number (error values) |
How to read the table:
- If a minute has no row, the signal did not change in that minute; the previous value still applies.
- If
value_min,value_maxandvalue_avgare empty (NULL) andvalue_invalidis greater than 0, only error values arrived in that minute. The curve should show a gap there, not a line. - The table is not split into day slices. As with the raw values, the time condition goes
directly on the column, here
minute_unix_nanos. - Minute values are kept for 730 days (but at most 4 GB, about 130 MB per signal and year); status signals, whose value is an object, have no minute values, far longer than the raw values. A range for which no raw values are left can still be shown from the minute values.
- The DataStore computes the minute values in the background, not when it stores a value. After the update to 2.47.22 it also computes them for the existing data, from today backwards; its status view shows the progress under Minute values. If it falls more than 15 minutes behind, the edge reports 1537.
When to use minute values: as soon as one point of the time series covers a minute or
more, that is $__interval_ms >= 60000. With Max data points = 1000 that is the case
from a range of a little over 12 hours: Grafana rounds the point width, “Last 12 hours”
gives 30 s, “Last 24 hours” already 60 s. Below that, use the raw values as in section 3; one minute
value would have to fill more than one point there.
One query that picks its source itself
The two time series of the shipped dashboard send one query that contains both tables.
Each half checks $__interval_ms and returns rows only when it is its turn. Zooming
therefore switches between raw values and minute values by itself. This is the query of the
panel “IDEA-4S Vibration Velocity”: the maximum per point as the line, the minimum as a band
below it.
SELECT
to_timestamp(bucket * $__interval_ms / 1000.0) AS "time",
max(v_max) FILTER (WHERE signal_name = 'VibVeloXDirection') AS value_effective_vibration_velocity_xdirection,
max(v_max) FILTER (WHERE signal_name = 'VibVeloYDirection') AS value_effective_vibration_velocity_ydirection,
max(v_max) FILTER (WHERE signal_name = 'VibVeloZDirection') AS value_effective_vibration_velocity_zdirection,
min(v_min) FILTER (WHERE signal_name = 'VibVeloXDirection') AS min_vibration_velocity_xdirection,
min(v_min) FILTER (WHERE signal_name = 'VibVeloYDirection') AS min_vibration_velocity_ydirection,
min(v_min) FILTER (WHERE signal_name = 'VibVeloZDirection') AS min_vibration_velocity_zdirection
FROM (
-- raw values while a point is shorter than a minute
SELECT r.bucket, r.signal_name, r.v AS v_max, r.v AS v_min, r.v AS v_avg
FROM (
SELECT
hv.source_time_unix_nanos / ($__interval_ms::bigint * 1000000) AS bucket,
hv.signal_name,
(hv.value #>> '{}')::double precision AS v
FROM "historicValues" hv
WHERE $__interval_ms < 60000
AND hv.machine_id = COALESCE(NULLIF('${machine}', '')::bigint, (SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND hv.signal_name IN ('VibVeloXDirection', 'VibVeloYDirection', 'VibVeloZDirection')
AND hv.source_time_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND hv.source_time_unix_nanos < $__unixEpochTo()::bigint * 1000000000
AND jsonb_typeof(hv.value) = 'number'
) r
UNION ALL
-- minute values from one minute per point on (DataStore 5.138.0, historicValuesMinute)
SELECT
m.minute_unix_nanos / ($__interval_ms::bigint * 1000000) AS bucket,
m.signal_name,
m.value_max AS v_max,
m.value_min AS v_min,
m.value_avg AS v_avg
FROM "historicValuesMinute" m
WHERE $__interval_ms >= 60000
AND m.machine_id = COALESCE(NULLIF('${machine}', '')::bigint, (SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND m.signal_name IN ('VibVeloXDirection', 'VibVeloYDirection', 'VibVeloZDirection')
AND m.minute_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND m.minute_unix_nanos < $__unixEpochTo()::bigint * 1000000000
) sub
GROUP BY bucket
ORDER BY bucket
The panel “IDEA-4S Temperature Bearings” shows the mean. Its query has the same inner part
with the four bearing signals; the outer part uses avg(v_avg) instead of max/min:
SELECT
to_timestamp(bucket * $__interval_ms / 1000.0) AS "time",
avg(v_avg) FILTER (WHERE signal_name = 'TempBearing1') AS value_temperature_bearing_1,
avg(v_avg) FILTER (WHERE signal_name = 'TempBearing2') AS value_temperature_bearing_2,
avg(v_avg) FILTER (WHERE signal_name = 'TempBearing3') AS value_temperature_bearing_3,
avg(v_avg) FILTER (WHERE signal_name = 'TempBearing4') AS value_temperature_bearing_4
FROM (
-- raw values while a point is shorter than a minute
SELECT r.bucket, r.signal_name, r.v AS v_max, r.v AS v_min, r.v AS v_avg
FROM (
SELECT
hv.source_time_unix_nanos / ($__interval_ms::bigint * 1000000) AS bucket,
hv.signal_name,
(hv.value #>> '{}')::double precision AS v
FROM "historicValues" hv
WHERE $__interval_ms < 60000
AND hv.machine_id = COALESCE(NULLIF('${machine}', '')::bigint, (SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND hv.signal_name IN ('TempBearing1', 'TempBearing2', 'TempBearing3', 'TempBearing4')
AND hv.source_time_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND hv.source_time_unix_nanos < $__unixEpochTo()::bigint * 1000000000
AND jsonb_typeof(hv.value) = 'number'
) r
UNION ALL
-- minute values from one minute per point on (DataStore 5.138.0, historicValuesMinute)
SELECT
m.minute_unix_nanos / ($__interval_ms::bigint * 1000000) AS bucket,
m.signal_name,
m.value_max AS v_max,
m.value_min AS v_min,
m.value_avg AS v_avg
FROM "historicValuesMinute" m
WHERE $__interval_ms >= 60000
AND m.machine_id = COALESCE(NULLIF('${machine}', '')::bigint, (SELECT id FROM "machines" WHERE import_type = 'idea4s' ORDER BY id LIMIT 1))
AND m.signal_name IN ('TempBearing1', 'TempBearing2', 'TempBearing3', 'TempBearing4')
AND m.minute_unix_nanos >= $__unixEpochFrom()::bigint * 1000000000
AND m.minute_unix_nanos < $__unixEpochTo()::bigint * 1000000000
) sub
GROUP BY bucket
ORDER BY bucket
What matters:
- Both halves return the same columns (
bucket,signal_name,v_max,v_min,v_avg). For raw values all three are the raw value itself. - The condition
$__interval_ms < 60000or>= 60000is in both halves. Only then does the database read just one table each time. max,minandavgskip empty values. A signal’s point stays empty when the signal had only error values or no minute row in that slice.- The mean of a point made of several minutes is the mean of the minute means; every minute counts the same.
The panel needs these settings:
- Max data points = 1000 under Query options, as in section 3.
- Connect null values set to Threshold with 60 s (
"spanNulls": 60000in the dashboard JSON). Grafana connects two values of a curve with at most 60 s without a value between them. Less is not enough: an unchanged value arrives only about every 30 s, sometimes a second later. It shows longer stretches without a value as a gap, as long as other columns of the query have values there. With minute values one point covers 60 s or more, so every empty point is a gap there, including one without a minute row in which the previous value still applied. - The band: one override per axis, Fields with name = the maximum column (e.g.
value_effective_vibration_velocity_xdirection), property Fill below to = the matching minimum column (min_vibration_velocity_xdirection). The minimum column itself gets Line width 0 and is hidden from the legend. In the shipped dashboard the panel also has Fill opacity 12.
5. Pick the machine with the variable
If several IDEA-4S are connected to the edge, pick the machine with the dashboard variable
machine, as in the examples above. Do not copy one panel per machine with OFFSET 1,
OFFSET 2 and so on: the order of the machines changes when one is created anew, and the
panel then shows a different machine without any notice. How to create the variable is
described under
Picking the machine with a dashboard variable.
6. What to expect
Grafana stops a query after 120 seconds; the panel then shows an error. How long a query takes depends mostly on whether the edge has to read the data from its flash storage or still has it in memory.
Raw-value queries (pattern from section 3, without minute values), measured on a test edge with about 20 GB of measured values, data read from flash for the first time:
| Time range | Load time of the raw-value query |
|---|---|
| 24 hours | 1–2 s (measured with the dashboard before 2.47.22) |
| 7 days | 13 s (dashboard before 2.47.22: 58 s) |
| 14 days | 34 s |
| 30 days | over 120 s, runs into Grafana’s limit |
Loading 7 days again shortly afterwards takes only a few seconds. A raw-value query without downsampling or with a converted time condition takes several times as long.
Queries with minute values (pattern from section 4, shipped dashboard from firmware 2.47.22):
| Time range | Load time with minute values |
|---|---|
| 24 hours | 0.04 s (the same query from raw values only: 1.5 s) |
| 7 days | 0.05 s (from raw values only: about 11 s) |
| 30 days | 0.1 s (second test edge with 52 days of data; from raw values only 6 s there, 30 s on the first read) |
Measured on a test edge with 17.7 million measured values, vibration velocity of three axes; first and repeated loading do not differ measurably.
This means:
- Use the minute values for long ranges. A pure raw-value query over more than 14 days easily runs into the limit. Evaluate raw values over long ranges in parts or export them (Export measurement data to Excel).
- An auto-refresh every second only suits short ranges. Each refresh reloads the whole range, even though a point made of minute values changes at most once a minute. For long ranges, switch it off or choose a few minutes.
7. Checklist
Before you save a panel:
- Signal name spelt as in the signal list
(e.g.
RotSpeed, notSpeed) - Machine via
${machine}with a fallback to the first IDEA-4S, no fixed number - Time condition directly on
hv.source_time_unix_nanos AND jsonb_typeof(hv.value) = 'number'- Time series: integer
bucket, timestamp only in the outer query,avgormax - Time series: Max data points = 1000
- Time series over long ranges: minute values from
$__interval_ms >= 60000, the condition in both halves of the query, Connect null values at 60 s - Tile with the latest value: 24-hour window,
ORDER BY … DESC LIMIT 1 - Tested with the longest range you want to offer