How to pass timerange filter for postgres query

Problem Statement : We are using sqlite datasource to build dashboards. we are getting data with below query but we want to filter it based on time range and also real time data. ex: every 6m the dashboard to be refresh and change the values. So, can some one help me to how we can pass the time interval of 6m in query to refresh it every time.

Select Date_n_Time, SensorID, Temperature from dht22_temperature_Data

Step to achive this follow the steps mention below
Step 1: Create table and insert real time data in it, in my case I use postgresql , you can use your sqlite datasource as well.


Step 2: Create dashboard and select time series visualizations

Step 3 : Use below query to fetch data from db and display data on panel.

Filter Data Based on Time Range

In Grafana, use the query with __timeFilter(Date_n_Time) to filter data within the dashboard’s selected time range:

Step 4: Enable Auto Refresh (Every 6 Minutes)

  1. Go to the Dashboard Settings in Grafana.
  2. Set the Refresh Interval to 6m .
  3. Save the settings.

This ensures the query runs every 6 minutes to fetch the latest data.

Final output:

2 Likes

nice post! Well explained

1 Like

Thank you for your kind words! We’re glad you found the post helpful. If you have any questions or need assistance in the future, please don’t hesitate to reach out to us. We’re always here to help! :blush: