Dear experts,
I’m storing data from a bunch of sensors in an InfluxDB database (to monitor them in Grafana).
Besides the actual sensor readings I also want to monitor if the sensors are sending regularly new values, since the sensors use a wireless connection that may have problems.
Since I know the interval at which the sensors are supposed to send data, my idea was to count the sensor entries in the database for a given time frame.
More hands on: when a sensor is supposed to send a new value each 5 min I expect 12 sensor values per hour.
I tried this query:
SELECT count("temperature") FROM "room_temp" WHERE ("device_id"::tag = 'xyz') GROUP BY time(60m)
That’s not too bad but has two issues:
-
It looks kind of ahead.
Example: now it’s 10:18. Hence I have received a sensor value at 10:00, 10:05, 10:10, 10:15 → the count is 4. I have a plotted point in my Grafana visualization with the time stamp 10:00 with the value 4. Looks at 1st glance as if there is an issue, since I expect 12 sensor values per hour, not 4.
Only at 10:55 I will have the expected number of 12 sensor readings.
What I want achieve is that the queried value with time stamp 10:00 looks back, i.e counts the received sensor values between 9:00 and 9:59.
I tried to use anoffset_interval
→... GROUP BY time(60m, -60m)
, but that didn’t change anything. -
The example above is not entirely realistic, since the sensor are comparably simple, they are not aware of the actual time. The only can keep their sending interval (e.g. 5 min). Whenever you switch them on, they will send their 1st sensor value and the next one 5 min later. And even this 5 min are due to a few seconds deviation.
Again an example: sensor value received at 10:04:59. Next is received after 5:02 at 10:10:01, then 10:15:03 and so on. The 12th value in this row will be received at 11:00:21. Therefore the above query will return only 11 sensor values between 10:00:00 and 11:00:00. Looks like I have lost one sensor value, but it’s not the case.
To make the query even better I would like to look 60 min back, but not from the full hour but from the timestamp of each sensor value entry in the influxdb database.
Is there a way to achieve that? Preferably in InfluxQL, since I have avoided to look into FLUX up to now.