Cumulative sum influxdb data
How to - Cumulative sum for kWh that resets daily
charts - How do I show a cumulative sum of each series in a Grafana multi series? - Stack Overflow
Cumulative graph?
After contacting grafana directly I received the answer that this is not currently possible. All such computation must be done by the data source, not by grafana.
Not exactly an answer to the original question but since the answer is "It's impossible" I thought I'd share my work-around for this missing feature. As this is what I did instead.
Here is how to do it in MariaDB:
SET @cumul := 0;
SELECT
`seq`
, @cumul := @cumul + `seq` AS `cumul`
FROM seq_1_to_20;
The data has to be ordered in sequence for it to add up correctly.
to explain it:
- set a variable called @cumul
- add the value you want to make cumulative and select it as a column
EDIT:
In Grafana it does not let you run 2 queries at the same time and it also makes use of Connection Pooling, meaning it speeds up the system by running queries over different connections, so if you run them as 2 queries the variable is not reset.
After hacking at it, this version works in Grafana for MariaDB (and probably MySQL too)
SELECT
`seq`
, @cumul := @cumul + `seq` AS `cumul`
FROM seq_1_to_20, (SELECT @cumul:= 0) b
I have an InfluxDB containing a field with distances since the last measurement. If I make a graph of this field, I get a graph fluctuating around few meters, since the speed is around a few meters per second.
I want a graph of the total distance travelled, but if I choose aggregate functions SUM or INTEGRAL, I get more or less the same graph as without. For one thing, this graph should be increasing over the entire interval.
If I read the InfluxDB documentation here https://influxdbcom.readthedocs.io/en/latest/content/docs/v0.6/api/aggregate_functions/#sum, it seems that SUM is exactly what I want, yet I don't really see a difference.