Juan Sebastian
Juan Sebastian

Reputation: 1077

Any way to have key/value pairs as template variables on grafana?

i am building a couple dashboards using grafana and i found the templating feature to be very useful, however i am monitoring some ec2 instances and getting some metrics from cloudwatch's ec2 namespace, however those use the instanceid as parameter, since the instanceid is not really human readable, which brings me to my question:

Is there any way to have key/value pairs as templating variables for a dashboard? that way people would see the hostname, select it, and the right instanceid would be fed to the panels,

Thanks in advance

Upvotes: 1

Views: 8629

Answers (2)

Topper Harley
Topper Harley

Reputation: 306

If you are using PostgreSQL as source of data(and may be same thing works for other data sources), you can just query:

SELECT hostname AS __text, id AS __value FROM host

And it will do everything else itself

Taken from official docs

Upvotes: 1

Daniel Lee
Daniel Lee

Reputation: 7969

Grafana has ad-hoc filter variables since v4.0 of Grafana but unfortunately the Cloudwatch data source does not yet support them. (InfluxDB, Elasticsearch and Prometheus have support).

You can however chain template variables so that a parent template variable can be passed to a child template variable. Here is a demo of that (using Graphite but the principle is the same).

And this Cloudwatch dashboard on Grafana.com also uses this feature:

https://grafana.com/dashboards/590

Cloudwatch dashboard

This is a child template variable (below). The other template variable values get passed into the query for Dimension Value - dimension_values($region, $namespace, $metric, $dimension)

Template Variable Editor

Upvotes: 1

Related Questions