Saving Custom queries as template variable

  • What Grafana version and what operating system are you using?
    I am currently using grafana 8.5.4 and mac os 12.4
  • What are you trying to achieve?
    I am trying to save a custom PromQL query as a template variable which i can use in multiple panel dashboards.
    I want to plot a overall health dashboard for my systems. If a value in a panel goes beyond warning threshold but below error threshold then I am plotting it as 1 (or in yellow color) if it goes beyond error threshold then i am plotting as 2(or red color) in another panel.

I have a separate result panel which tracks threshold breach in 3 different panels.

  • How are you trying to achieve it?
    I am planning to use following queries
    warning - (vector(1) and on() (25 <metrics_size >0)) or on() vector(0)
    error - (vector(2) and on() (metrics_size <0)) or on() vector(0)

I have to create 6 different queries (2 for each panel) for result panel.
Can we store this as template query? where i can just change threshold values and metrics name?

If yes how to achieve that. I really appreciate if you suggest any alternate feasible solution for this problem.