-1

How to use selected time range on Grafana dashboard in the panel query?

The panel I am choosing is a pie chart. I set the values as seconds. I query from my SQL database table extra data in seconds to subtract from the time range in seconds: Grafana dashboard time range in seconds - my query result should be the result.

I tried to use the answers from this thread, though it didn't help out.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • 1
    Well, something like `select ($__to - $__from)/1000 as "range"` will return you time range of your dashboard in seconds. Is that what you need? – markalex Jul 24 '23 at 17:20
  • @markalex thank you, it worked, could you add it to the answers section please so that I accept it – Arseniy Sleptsov Jul 25 '23 at 09:31

1 Answers1

1

You can get length of time range in seconds used by dashboard with the following query:

select ($__to - $__from)/1000 as "range"

Then you can use this expression as part of any query as usual.

markalex
  • 8,623
  • 2
  • 7
  • 32