Math operations on field value and time

influxdb
#1

I want to subtract the timestamp in epoch seconds from a field value (also in epoch seconds). Is this possible?

#2

No, this is not currently possible, but we always welcome new feature requests on GitHub.

Currently, fields support integers, floats, booleans, and strings, and there is no way to cast a integer, float, or string to a timestamp in order to do the comparison.

What are you trying to accomplish? Would it be possible to perform this calculation before writing the points to the database, and storing the difference instead of the timestamp?

#3

I am trying to analyze the difference between when my data was logged into database and when it was measured by a node. The time it was logged into the database is recorded in a field value as a unix epoch. The time it was measured is just recorded as the time in influx. Yes it could be precomputed, but that isn’t a very scalable solution for me. It doesn’t make sense to add more and more columns of precomputed derivations of the base data from a storage perspective. Maybe it would make sense from a performance perspective if it were difficult to calculate the derived value or it were used very often - neither of those is the case for me.

#4

I’ll suggest a workaround until such a feature makes its way into InfluxDB.

You could do the calculation client side.
What client (and programming language) or dashboard software do you use?

#5

I had a similar problem in InlfuxQL:

SELECT time - kafka_time FROM “kafka”.“autogen”.“mtm1m3-accelerometerdata”

to measure the latency of a message produced by Kafka.

kafka_time is a Unix timestamp field in the “mtm1m3-accelerometerdata” measurement.

Unfortunately, that query does not work and I ended up extracting the data and computing the latency outside InfluxDB.

Would a query like that work in Flux?