Influxdb querying values from 2 measurements and using SUM() for the total value

2.6k views Asked by At
select SUM(value) 
from /measurment1|measurment2/ 
where time > now() - 60m  and host = 'hostname' limit 2;

Name: measurment1

time                sum
----                ---
1505749307008583382 4680247

name: measurment2

time                sum
----                ---
1505749307008583382 3004489

But is it possible to get value of SUM(measurment1+measurment2) , so that I see only o/p .

1

There are 1 answers

0
danny On

Not possible in influx query language. It does not support functions across measurements.

If this is something you require, you may be interested in layering another API on top of influx that do this, like Graphite via Influxgraph.

For the above, something like this.

/etc/graphite-api.yaml:

finders:
  - influxgraph.InfluxDBFinder
influxdb:
  db: <your database>
  templates:
    # Produces metric paths like 'measurement1.hostname.value'
    - measurement.host.field*

Start the graphite-api/influxgraph webapp.

A query /render?from=-60min&target=sum(*.hostname.value) then produces the sum of value on tag host='hostname' for all measurements.

{measurement1,measurement2}.hostname.value can be used instead to limit it to specific measurements.

NB - Performance wise (of influx), best to have multiple values in the same measurement rather than same value field name in multiple measurements.