timestampinfluxdbinfluxdb-2

Can I double timestamp measurements on Influxdb 2.6?


I have an external device that sends data with timestamps to influx. I enter them in influxdb 2.6 and influxdb recognizes that timestamp, so it doesn't add a new one when data arrives. However, I would like to have that second timestamp to know exactly when the measurement arrives and to study the latency. Is it possible?

I don't need the second timestamp to be in timestamp format, it could be like a tag or something, but I don't want to change the first timestamp, the one from the external device, because it is the one I will use in the queries.


Solution

  • You can send every data point twice, in the same batch of line protocol lines - one with the timestamp and the other without it, to a different measurement with field (eg. actual_time for the sake of an example) holding the explicit timestamp value.

    You could then join the two streams and calculate the latency, like

    join.inner(
        left: s1,
        right: s2,
        on: (l, r) => l._time == r.actual_time,
        as: (l, r) => ({l with latency: r._time - l._time}),
    )