Influxdb and Grafana combine multiple SELECT

aggregateselect

I have some network counters in Influx that I graph with Grafana.

I'm trying to combine stats from a couple ethernet interfaces and combine them to show aggregate bandwidth.

These two separate queries work on their own, but I can't figure out how to write it to combine these two.

SELECT 8 * non_negative_derivative(mean("value"), 1s ) 
FROM "inoctets" 
WHERE "host" = 'myhost1' AND $timeFilter 
GROUP BY time(1s) fill(null)

SELECT 8 * non_negative_derivative(mean("value"), 1s ) 
FROM "inoctets" 
WHERE "host" = 'myhost4' AND $timeFilter 
GROUP BY time(1s) fill(null)

Edit: FWIW I'm running Influx 1.1.1 and Grafana 4.1.1

Best Answer

To combine aggregated measurements under different tags is a bit tricky. I managed to find this post which has the answer.

The key is to use sub-queries (InfluxDB 1.2+) to capture each tag's measurements separately. Then, since the field names are the same, they need to be renamed. Finally you can manipulate them as needed. Here's your example:

SELECT 8 * (non_negative_derivative(mean("inoctets1"), 1s )
          + non_negative_derivative(mean("inoctets4"), 1s ))
AS "inbytestotal"
FROM (
    SELECT "value"
    AS "inoctets1"
    FROM "inoctets"
    WHERE "host" = 'myhost1' AND $timeFilter
), (
    SELECT "value"
    AS "inoctets4"
    FROM "inoctets"
    WHERE "host" = 'myhost4' AND $timeFilter
)
GROUP BY time(1s) fill(null)