Influxdb and grafana: howto create series that is the sum of two other series

influx-db

I have these three queries. They show the average upload speed of three different docker containers over time:

enter image description here

The difference() call is needed, because the data contains cumulative "bytes_sent" values, and it never decreases.

Here is an example of the output:

enter image description here

I would like to create a third series that shows the sum of the above three graphs. If I simply remove the WHERE condition the it won't work:

enter image description here

The reason for this is that mean() always precedes difference(), and the mean value of these independent cumulative sums is meaningless:

enter image description here

The correct solution would be to calculate the three difference values and add them together. But I don't know how to do this in grafana?

Obviously the very best solution would be to store the differences in the database in the first place. Unfortunately, I'm not the one who is sending the data so I can't do anything about it.

Best Answer

In theory, switch Grafana query editor to the raw mode and write a query where you use a subquery - outer query will just sum data precalculated by inner query:

SELECT SUM(field_from_main_query) FROM (
  <your current Grafana query with GROUP BY time(10s) hostname>
) GROUP BY time(10s)