Drop-down list of predefined queries?

Hello, Team. Please let us know if it possible to create a drop-down list of predefined SQL/Lucene/KQL/etc. queries in Grafana panel. It might look similar to what exists in “Explore” the data source. But it has to be a panel in a dashboard. We would gladly consider ANY possible options like queries stored in Infinity data source, using other panel as a data source, Saved Queries feature (if it really exists in Grafana), etc. Any ideas and references are very welcome! We read though all available Grafana docs, demos, and showcases. The solution design is not clear for some reason. Many thanks! Dmitri

and how will you use these? what is the requirement?

Firstly - totally release user from manual entry of SQL codes. Just to let him/her simply push the button with a query name.
Secondly - to execute the same query against multiple different targes (hosts, etc.), determined by variables.

1 Like

doable but sounds very brittle to me imo

why not have 2 instanves of grafana one pointing to dev one to prod?

also with this approach guaranteed you will be dabbling with dynamic sql and parsing etc, which are prone to break
and notorious for perf issues.

for ex. lets say you have a query that takes parameters how would you handle that

We work with many data sources, having many targets, and we already use a tree of Grafana chained variables implemented. They allow to implement many-to-many conditions in Grafana panels. Thus, we already have several drop-down lists - working perfectly well! And we want to add another feature - “labeled stored queries”. There could be just 10-12 of them, and we plan to execute them, based on selected target. Is it possible to select and execute a stored query? We see many of them available among Dashboard data source type, as an option. So, we want to build a panel, which selects a query from a drop-down list, executes it, and returns result to the panel. What would you recommend for such solution in Grafana? Many thanks.

in what db technology?

in ms sql you can do exec dbo.getTransportationPlans()

I would not recommend you use inline queries, use artifacts such as stored procedures . So all this can done using a database even a csv or json file where you store all of your queries in two+ column table

displayname,query
Fetch Transportation,exec dbo.getTransportationPlans()

Create custom variable (e.g. query) and define SQL queries there (properly escape what variable needs to escape):

Then use that variable in the panel as ${query:raw}. Of course, don’t expect that everything will be working magically. Just iterate and improve all the problems then.

1 Like

Currently we use Elasticsearch, Prometheus, Splunk, and Zabbix as our “databases”. Or better to call them data sources, which is what it is. And we select log type data from them.

variable

1 Like

Where are those queries stored? In Grafana custom variable?

but I would not do what I did. nope. I would save that combo in a db. dont do it inline like I did in the definition, it was just for a quick and dirty poc

Save it in Grafana Infinity “db”?

that is not a db. save it where your grafana admin recommends to save it.

Correct, and I called “db”, but not db. But in fact, we already use it In Grafana for small data collections. It works good like a local “db”.

1 Like

true you can but developer of that plugin recommends to use that approach only for vetting purposes.

[{"__text":"Rail Road Tracks","__value":"railroadtracks_sp 'CA' "}]

image

Thank you very much for sharing your ideas. We are still open to any available related Grafana techniques, plugins and tricks - if they really exist. For example, Grafana Grot recommended using “Saved Queries”. But NONE references found in Grafana docs.

stored procedures are saved queries

the second __value column is saved query. saved in infinity db

Have you tried Grafana Library Panels?

Yes, we tried library panels. Do you mean a library panel can store a query, and it can be used as a Dashboard type data source in another panel? If so, it should not be necessarily to be a library one?