Wednesday, February 8, 2017

Grafana - Template Variables With Custom Text

This tutorial explains a workaround for a feature of the Grafana 2.5.0. Yes it's an old version and upgrading to 3.0.1 removes the need for this workaround but sometimes I don't get to choose my versions at work.

When creating a template variable, the "text" and "value" of the variable are the same. By inspecting the JSON of a dashboard, you can see this in the snippet below.

        "options": [
          {
            "selected": false,
            "text": "Prod",
            "value": "Prod"
          },


The issue arises when I want a "value" that is different than the "text". For example, I would like the "value" to be a group of hosts like this: 

        "options": [
          {
            "selected": false,
            "text": "Prod",
            "value": "host[1-3]name"
          },
          {
            "selected": false,
            "text": "Test",
            "value": "host[4-6]name"
          },

To get this to work, the JSON must be edited outside of Grafana. So, export the dashboard, edit it in your favorite editor and then import it back into Grafana. Also, don't modify the template variable using the Grafana template variable editor. If you do, the "values" will change to match the "text"s.


No comments:

Post a Comment