Hello. I am trying to understand how to use Grafana to show machine usage. I am collecting data from our 18 machines in an influxdb database and each machine is constantly writin 1 (idle), 2 (running) and 3 (alarm).
I would like to create a visualisation for how much of the day the machine have been running, or how long it has been in alarm-mode.
For example during last 24 hours machine 5 has been idle 3h, running 20,5h, alarm 30min. Or maybe get the result in a percentage.
Not sure if this is the right place to ask, but Im hoping for a kind soul to point me in the right direction.
If you are using flux, you may try stateDuration function to solve your task
Im a bit new to this and I cant figure out how to use stateDuration. It had me pointed in some other directions tho so this is how far I hace come now:
That gives me the result of how many minutes during the given time range the value of “singlestatus” is greater or equal to 2. (the status that shows that the machine is running)
How do I make this a percentage of the time range? For example if I set the time range to 24h and I get the result that the machine have been running 16,5h, I would like the result to show 69% instead. I cant figure out if its possible to make math calculations of the result when using transformations.
I have no idea if this i any way near the best way of doing this, and if not, feel free to give me any other suggestions. Thankyou.
Hi @dernebo
The state duration function that @ebabeshko linked to is for the Flux query language, and you are using InfluxQL, so it won’t work.
Looks like you may have found a workaround using the Grafana transformation. Not sure you can calculate the machine usage in minutes using InfluxQL, but this thread might be a good start.