Menu
Grafana Cloud Enterprise Open source

Variables

Note: Looking for prebuilt Grafana dasards? Check out our full library of dasards and more โ†’

The following topics describe how to add and manage variables in your dasards:

A variable is a placeholder for a value. You can use variables in metric queries and in panel titles. So when you change the value, using the dropdown at the top of the dasard, your panelโ€™s metric queries will change to reflect the new value.

Variables allow you to create more interactive and dynamic dasards. Instead of hard-coding things like server, application, and sensor names in your metric queries, you can use variables in their place. Variables are displayed as dropdown lists at the top of the dasard. These dropdowns make it easy to change the data being displayed in your dasard.

Give it a try using Grafana Play

With Grafana Play, you can explore and see how it works, learning from practical examples to accelerate your development. This feature can be seen on Templating - Global variables and interpolation.

Variables are useful for administrators who want to allow Grafana viewers to adjust visualizations without giving them full editing permissions. Grafana viewers can use variables.

Variables and templates also allow you to single-source dasards. If you have multiple identical data sources or servers, you can make one dasard and use variables to change what you are viewing. This simplifies maintenance and upkeep enormously.

Templates

A template is any query that contains a variable.

For example, if you were administering a dasard to monitor several servers, you could make a dasard for each server. Or you could create one dasard and use panels with template queries like this one:

wmi_system_threads{instance=~"$server"}

Variable values are always synced to the URL using the syntax var-<varname>=value.

Additional Examples

Variables are listed in drop-down lists across the top of the screen. Select different variables to see how the visualizations change.

To see variable settings, navigate to Dasard Settings > Variables. Click a variable in the list to see its settings.

Variables can be used in titles, descriptions, text panels, and queries. Queries with text that starts with $ are templates. Not all panels will have template queries.

The following dasards in Grafana Play provide examples of template variables:

Variable best practices

  • Variable drop-down lists are displayed in the order they are listed in the variable list in Dasard settings.
  • Put the variables that you will change often at the top, so they will be shown first (far left on the dasard).
  • By default, variables donโ€™t have a default value. This means that the topmost value in the drop-down is always preselected. If you want to pre-populate a variable with an empty value, you can use the following workaround in the variable settings:
    1. Select the Include All Option checkbox.
    2. In the Custom all value field, enter a value like +.