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.

  • Actually, instead of mean() + difference() it should be spread() withouth difference. But it doesn't answer the question anyway.
    – nagylzs
    Commented Apr 13, 2018 at 9:49

1 Answer 1


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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.