13

I have defined a variable in a Grafana dashboard through Grafana dashboard settings Variable is of "Custom" type. I want this variable having a default value when dashboard is opened.

How can I set a default value ?

RandomCoder
  • 6,606
  • 6
  • 22
  • 28

2 Answers2

17
  1. Choose your default value in dashboard and then save dashboard.
  2. Tick "Save current variable values as dashboard default".
  3. Default value is now set to the value you chose.
RandomCoder
  • 6,606
  • 6
  • 22
  • 28
1

If you'd like to avoid ClickOps by interacting with Grafana UI to persist config changes, then you can modify Grafana's dashboard JSON model - this will allow you to share your dashboard.

Let's say that you have defined your custom variable (like on the image below), and you would like to set 1[m] as a default value.

enter image description here

Then what you should do next, is to find this variable definition in Grafana's dashboard JSON model (look at templating.list location) and set "selected" to true in "options" and add/modify "current" section. Your config should resemble below settings.

...
"current": {
  "selected": true,
  "text": "1m",
  "value": "1m"
},
"options": [
  {
    "selected": true,
    "text": "1m",
    "value": "1m"
  },
  {
    "selected": false,
    "text": "3m",
    "value": "3m"
  },
  ...
],
...
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124