Runtime of devices

I monitor pumps and valves. What I have in the database is 1 for “on” and 0 for “off” every minute. What I want is a graph wich reflects the time a pump is running or a valve is open for the currently active time period.

How to get this?

What about sum()?

That will add up all the 1s and tell you how many minutes of on-time you had
in the time period.

Antony.

yes, but group by what?

I want the resulting graph look like the red line in this hand drawn example:

Why group by anything?

Just add up all the values in the time period which match the device name.

Antony.

I don’t find a way to make this work. Data looks like this:

t1 - 0
t2 - 0
t3 - 1
t4 - 1
t5 - 1
t6 - 0

where t1 to t6 are the timestamps and 0 and 1 are the values. The graph should reflect this:

t1 - 0
t2 - 0
t3 - 1
t4 - 2
t5 - 3
t6 - 3

Oh, sorry, I thought you wanted a single value for the time period which told
you how many minutes the pump or valve was “on” for.

I didn’t realise you were looking for something cumulative.

So, how about using integral()?

Antony.

I find no way to make it work with integral() … I think I need some thing like this:

https://docs.influxdata.com/influxdb/v1.7/query_language/functions/
#cumulative-sum

maybe?

Antony.

Thanks, haven’t found it because Grafana does not offer it in it’s point&klick interface … works.