2022-05-26 23:06:25 +08:00
---
aliases:
2023-09-28 20:04:07 +08:00
- ../variables/ # /docs/grafana/< GRAFANA VERSION > /variables/
- ../variables/templates-and-variables/ # /docs/grafana/< GRAFANA VERSION > /variables/templates-and-variables/
- ../variables/variable-examples/ # /docs/grafana/< GRAFANA VERSION > /variables/variable-examples/
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- cloud
- enterprise
- oss
2022-09-10 03:44:19 +08:00
title: Variables
2023-12-15 03:15:55 +08:00
description: Add variables to metric queries and panel titles to create interactive and dynamic dashboards
2024-09-25 04:12:08 +08:00
weight: 800
2022-05-26 23:06:25 +08:00
---
2020-05-16 04:58:39 +08:00
2022-09-10 03:44:19 +08:00
# Variables
2025-07-26 02:48:10 +08:00
A variable is a placeholder for a value.
When you change the value, the element using the variable will change to reflect the new value.
2024-02-17 02:28:56 +08:00
2025-07-26 02:48:10 +08:00
Variables are displayed as drop-down lists (or in some cases text fields) at the top of the dashboard.
These drop-down lists make it easy to update the variable value and thus change the data being displayed in your dashboard.
2022-09-10 03:44:19 +08:00
2025-07-26 02:48:10 +08:00
For example, if you needed to monitor several servers, you _could_ make a dashboard for each server.
Or you could create one dashboard and use panels with variables like this one, where you can change the server using the variable selector:
2020-05-16 04:58:39 +08:00
2025-07-26 02:48:10 +08:00
{{< figure src = "/media/docs/grafana/dashboards/screenshot-selected-variables-v12.png" max-width = "750px" alt = "Variable drop-down open and two values selected" > }}
2020-05-16 04:58:39 +08:00
2025-07-26 02:48:10 +08:00
Variables allow you to create more interactive dashboards.
Instead of hard-coding things like server, application, and sensor names in your metric queries, you can use variables in their place.
They're useful for administrators who want to allow Grafana viewers to adjust visualizations without giving them full editing permissions.
2023-12-09 00:24:35 +08:00
2025-07-26 02:48:10 +08:00
Using variables also allows you to single-source dashboards.
If you have multiple identical data sources or servers, you can make one dashboard and use variables to change what you are viewing.
This simplifies maintenance and upkeep enormously.
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
{{< youtube id = "mMUJ3iwIYwc" > }}
2024-04-16 03:32:09 +08:00
2025-07-26 02:48:10 +08:00
You can use variables in:
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
- Data source queries
- [Panel repeating options ](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/panels-visualizations/configure-panel-options/#configure-repeating-panels )
- [Dashboard and panel links ](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/manage-dashboard-links/ )
- Titles
- Descriptions
- [Transformations ](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/panels-visualizations/query-transform-data/transform-data/ )
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
To see variable settings, navigate to **Dashboard Settings > Variables** .
Click a variable in the list to see its settings.
{{< docs / play title = "Templating - Interactive dashboard" url = "https://play.grafana.org/goto/B9Xog68Hg?orgId=1" > }}
## Template variables {#templates}
2020-10-02 05:37:26 +08:00
A _template_ is any query that contains a variable.
2025-07-26 02:48:10 +08:00
Queries with text that starts with `$` are templates.
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
{{< admonition type = "note" > }}
In our documentation and in the application, we typically simply refer to a _template query_ as a _query_ , but we often use the terms _variable_ and _template variable_ interchangeably.
{{< / admonition > }}
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
For example, if you were administering a dashboard to monitor several servers, it could have panels that use template queries like this one:
```text
groupByNode(movingAverage(apps.$app.$server.counters.requests.count, 10), 2, 'sum')
2020-10-02 05:37:26 +08:00
```
2025-07-26 02:48:10 +08:00
The following image shows a panel in edit mode using the query:
{{< figure src = "/media/docs/grafana/dashboards/screenshot-template-query-v12.1.png" max-width = "750px" alt = "A panel using a template query" > }}
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
### Variables in URLs
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
Variable values are always synced to the URL using [query parameter syntax ](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#query-parameters ), `var-<varname>=value` .
For example:
```text
https://play.grafana.org/d/HYaGDGIMk/templating-global-variables-and-interpolation?orgId=1& from=now-6h& to=now& timezone=utc& var-Server=CCC& var-MyCustomDashboardVariable=Hello%20World%21
```
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
In the preceding example, the variables and values are `var-Server=CCC` and `var-MyCustomDashboardVariable=Hello%20World%21` .
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
## Additional examples
2020-10-02 05:37:26 +08:00
2023-07-08 04:00:05 +08:00
The following dashboards in Grafana Play provide examples of template variables:
2025-07-26 02:48:10 +08:00
- [Templating - Repeated panels ](https://play.grafana.org/goto/yfZOReUNR?orgId=1 ) - Using query variables to control how many panels appear in a dashboard.
- [Templating - Nested Variables Drilldown ](https://play.grafana.org/d/testdata-nested-variables-drilldown/ ) - Demonstrates how changing one variable value can change the values available in a nested variable.
- [Templating - Global variables and interpolation ](https://play.grafana.org/d/HYaGDGIMk/ ) - Shows you how the syntax for Grafana variables works.
2022-09-09 21:38:17 +08:00
2025-07-26 02:48:10 +08:00
## Next steps
2020-10-02 05:37:26 +08:00
2025-07-26 02:48:10 +08:00
The following topics describe how to add and manage variables in your dashboards:
{{< section > }}