Dear Grafana team/users,
What I Want to Achieve:
I want to create a Grafana query where:
- Time is grouped into 15-second intervals.
- For each of these 15-second intervals, I want to calculate the count of
BoxID
records for the last hour preceding each 15-second interval.
In simpler terms, the goal is to:
- Group data by 15-second intervals.
- For each time interval, calculate how many
BoxID
records were logged in the previous hour up to that specific time interval.
Detailed Explanation of the Query:
- Group Data into 15-second Intervals: We need to take the timestamp of each record and group it into intervals of 15 seconds. This will give us discrete blocks of time on the x-axis of the graph.
- Count the
BoxID
Records for Each 15-second Interval: For each 15-second interval, we need to calculate how manyBoxID
entries were recorded in the last hour. This means for every 15-second timestamp, we look back one hour and count the total number ofBoxID
records in that time period.
Currently, I have the following query, which counts BoxID
records for 15-second intervals:
SELECT
$__timeGroup(Timestamp, ‘15s’) AS “time”, – Time interval grouped by 15 seconds
count(BoxID) – Counting BoxID for each 15-second interval
FROM
ACTIN_DP.dbo.PLC – Data source (PLC table)
WHERE
BR = ‘BR08’ – Filter for BR08 branch
AND $__timeFilter(Timestamp) – Time filter applied for the selected time range in Grafana
GROUP BY
$__timeGroup(Timestamp, ‘15s’) – Grouping by 15-second intervals
ORDER BY
“time” – Ordering the results by time
Thank you very much for your help! I appreciate any suggestions or improvements you can offer to modify this query for better clarity and accuracy!