Dear experts,
I am quite new in InfluxDB. I need your expertise for the following.
At present, I am in process of designing an Industry 4.0 solution.
We store some data in InfluxDB v2.7 database by using a gateway. The data we store in the measurements, got the following structure:
measurement_name, tag1=”Machine Name”, tag2=”Item Name”, tag3=”Type Name” field1=2 field2=32 unix_timestamp_1
measurement_name, tag1=”Machine Name”, tag2=”Item Name”, tag3=”Type Name” field1=2 field2=32 unix_timestamp_2
measurement_name, tag1=”Machine Name”, tag2=”Item Name”, tag3=”Type Name” field1=2 field2=32 unix_timestamp_3
measurement_name, tag1=”Machine Name”, tag2=”Item Name”, tag3=”Type Name” field1=2 field2=32 unix_timestamp_4
, etc.
These records represent states changing of certain devices – motors, valves etc.
The Unix timestamp is the moment of status change. The tag2 – Items, is a device identifier.
Let say that into the measurement, I have got additional field – “duration”.
Is there any trick, where the InfluxDB, automatically calculates the status duration, by subtracting from the current timestamp, the timestamp of the previous status change, of the same item?
If it was MS SQL, I would do it into the query itself! I would use subqueries or Common Table Expression. First I would select the data by ”Item Name” and timestamp – start and end time, next I would order then by timestamp and at the end I would use “window” function to access the previous row in order to subtract the time.
Probably any functionality as triggers is available?
Any advices regarding the design of such functionality will be highly appreciated!
Best Regards,
Svetozar