Uptime/operating hours per day

Hi There, i have done a lot of stuff with grafana already, but now i am a bit stuck…

I have several sensors that report 1 when the machine/heater is on, 0 when off. report interval of the sensors may differ over time.
I would like to display the operating hours per day for these 1/0 sensor values.

In the single stat it should show the avg hours per day for the selected timerange,
in the graph i would like to have the on-hours per day for the selected timerange.

I guess it must be quite simple to do that, but i am totally lost here. I tried to do something like sum(sensor) / count(sensor) which should give the avg over time, but i somehow need to agregate that to hours per day.

SELECT sum(“Brenner”) /count(Brenner) FROM “sensors” WHERE (“location” = ‘heizung’) AND $timeFilter GROUP BY time(1d) fill(null)

Thanks for your help/ideas.

I have a similar situation. My heater counts the secounds, when it is on. The counter pauses, when heater is off, and continues, when it goes on again. The value I send to influx every 5 secounds. Making a graph in grafana shows a horizontal line when heater is off and an “upward slope” when it was on. That’s ok so far, as I from the lenght of the slope I can see for how long it was on.

But I would like to have also a daily “on” time value. Is it possible somehow to tell grafana to look for the first and last value of the day/week/month and show only the difference?

Please review the submission template and include more details:

  • What Grafana version and what operating system are you using?
  • What is your datasource?
  • What visualization panel you are using e.g. time-series, bar chart, histogram etc?
  • What are you trying to achieve?
  • How are you trying to achieve it?
  • What happened?
  • What did you expect to happen?
  • Can you copy/paste the configuration(s) that you are having problems with?
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
  • Did you follow any online instructions? If so, what is the URL?

@mzsolnay If you are using Flux, you can probably do this using some special functions. See more here and post back when/if you get it working.

@derfrickler @mzsolnay

This is fairly simple to do using Flux stateDuration() function.

1 Like