Cumulative graph?

Hi.

I’m trying to work out whether, and if so how, the following is possible with
Grafana (version 5.4.3 if it matters):

I have an InfluxDB data set, which receives one numeric value per second from a
data source. This value may be zero, or a (usually small) positive integer.

I want to display a line graph of the cumulative sum of the values over the past
hour, getting one new data point per second (so, the value of each displayed
point is the sum of the previous 3600 values in the InfluxDB time series).

Assuming that is possible, can I further extend that idea by having the time
interval over which the values are summed (one hour in the above example)
automatically match the duration of the graph being shown in Grafana, so that
if I change the timescale of the graph, the calculation adjusts to sum the
values over the past 10 minutes, or 24 hours, or whatever I’ve chosen as the
duration of the graph’s X-axis?

Thanks,

Antony.

1 Like

I think you can do the second requirement (your further extension) just by selecting the Aggregate > Integral value.

[Edit] Hmm, no it doesn’t.

I use this query to show rainfall for the graph period, but I have the accumulated value stored in the db. This is for MySQL

SELECT
  $__timeGroupAlias(measured_at,$__interval),
  max(rain_total_mm)-@start AS "rain"
FROM samples AS tbl
CROSS JOIN (select @start := `rain_total_mm` from samples where measured_at>=$__timeFrom() limit 1) AS sub
WHERE
  $__timeFilter(measured_at)
GROUP BY 1
ORDER BY $__timeGroup(measured_at,$__interval)