2022-05-26 23:06:25 +08:00
---
aliases:
2022-12-10 00:36:04 +08:00
- ../../reference/templating/
- ../../variables/advanced-variable-format-options/
- ../../variables/syntax/
2022-05-26 23:06:25 +08:00
keywords:
- grafana
- templating
- documentation
- guide
- template
- variable
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-09 21:38:17 +08:00
title: Variable syntax
2023-12-15 03:15:55 +08:00
description: Learn about different types of variable syntax
2022-09-09 21:38:17 +08:00
weight: 300
2022-05-26 23:06:25 +08:00
---
2020-05-01 07:24:59 +08:00
2022-09-09 21:38:17 +08:00
# Variable syntax
Panel titles and metric queries can refer to variables using two different syntaxes:
- `$varname`
This syntax is easy to read, but it does not allow you to use a variable in the middle of a word.
**Example:** apps.frontend.$server.requests.count
- `${var_name}` Use this syntax when you want to interpolate a variable in the middle of an expression.
2023-09-13 17:39:04 +08:00
- `${var_name:<format>}` This format gives you more control over how Grafana interpolates values. Refer to [Advanced variable format options ](#advanced-variable-format-options ) for more detail on all the formatting types.
2022-09-09 21:38:17 +08:00
- `[[varname]]` Do not use. Deprecated old syntax, will be removed in a future release.
Before queries are sent to your data source the query is _interpolated_ , meaning the variable is replaced with its current value. During
interpolation, the variable value might be _escaped_ in order to conform to the syntax of the query language and where it is used.
For example, a variable used in a regex expression in an InfluxDB or Prometheus query will be regex escaped. Read the data source specific
documentation topic for details on value escaping during interpolation.
2023-09-13 17:39:04 +08:00
For advanced syntax to override data source default formatting, refer to [Advanced variable format options ](#advanced-variable-format-options ).
2022-09-09 21:38:17 +08:00
## Advanced variable format options
2020-05-01 07:24:59 +08:00
2020-11-10 04:26:49 +08:00
The formatting of the variable interpolation depends on the data source, but there are some situations where you might want to change the default formatting.
2020-05-01 07:24:59 +08:00
For example, the default for the MySql data source is to join multiple values as comma-separated with quotes: `'server01','server02'` . In some cases, you might want to have a comma-separated string without quotes: `server01,server02` . You can make that happen with advanced variable formatting options listed below.
2022-09-09 21:38:17 +08:00
### General syntax
2020-05-01 07:24:59 +08:00
Syntax: `${var_name:option}`
Test the formatting options on the [Grafana Play site ](https://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1 ).
If any invalid formatting option is specified, then `glob` is the default/fallback option.
An alternative syntax (that might be deprecated in the future) is `[[var_name:option]]` .
2022-09-09 21:38:17 +08:00
### CSV
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values as a comma-separated string.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:csv}'
Interpolation result: 'test1,test2'
```
2022-09-09 21:38:17 +08:00
### Distributed - OpenTSDB
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values in custom format for OpenTSDB.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:distributed}'
Interpolation result: 'test1,servers=test2'
```
2022-09-09 21:38:17 +08:00
### Doublequote
2020-05-01 07:24:59 +08:00
Formats single- and multi-valued variables into a comma-separated string, escapes `"` in each value by `\"` and quotes each value with `"` .
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:doublequote}'
Interpolation result: '"test1","test2"'
```
2022-09-09 21:38:17 +08:00
### Glob - Graphite
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values into a glob (for Graphite queries).
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:glob}'
Interpolation result: '{test1,test2}'
```
2022-09-09 21:38:17 +08:00
### JSON
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values as a comma-separated string.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:json}'
Interpolation result: '["test1", "test2"]'
```
2022-09-09 21:38:17 +08:00
### Lucene - Elasticsearch
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values in Lucene format for Elasticsearch.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:lucene}'
Interpolation result: '("test1" OR "test2")'
```
2022-09-09 21:38:17 +08:00
### Percentencode
2020-05-01 07:24:59 +08:00
Formats single and multi valued variables for use in URL parameters.
```bash
servers = ['foo()bar BAZ', 'test2']
String to interpolate: '${servers:percentencode}'
Interpolation result: 'foo%28%29bar%20BAZ%2Ctest2'
```
2022-09-09 21:38:17 +08:00
### Pipe
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values into a pipe-separated string.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1.', 'test2']
String to interpolate: '${servers:pipe}'
Interpolation result: 'test1.|test2'
```
2022-09-09 21:38:17 +08:00
### Raw
2020-05-06 05:37:34 +08:00
2025-05-16 22:48:36 +08:00
Doesn't apply any data source-specific formatting to the variable.
For example, in this case, there's a dashboard with a Prometheus data source and a multi-value variable.
Grafana typically converts the variable values as follows to accommodate Prometheus:
```bash
servers = ['test1.', 'test2']
String to interpolate: '${servers}'
Interpolation result: '(test1 | test2)'
```
Using the raw format, the values are returned without that formatting:
2020-05-06 05:37:34 +08:00
```bash
2025-05-16 22:48:36 +08:00
servers = ['test1.', 'test2']
String to interpolate: '${servers:raw}'
Interpolation result: 'test1,test2'
2020-05-06 05:37:34 +08:00
```
2022-09-09 21:38:17 +08:00
### Regex
2020-05-01 07:24:59 +08:00
2020-05-07 00:43:52 +08:00
Formats variables with multiple values into a regex string.
2020-05-01 07:24:59 +08:00
```bash
servers = ['test1.', 'test2']
String to interpolate: '${servers:regex}'
Interpolation result: '(test1\.|test2)'
```
2022-09-09 21:38:17 +08:00
### Singlequote
2020-05-01 07:24:59 +08:00
Formats single- and multi-valued variables into a comma-separated string, escapes `'` in each value by `\'` and quotes each value with `'` .
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:singlequote}'
Interpolation result: "'test1','test2'"
```
2022-09-09 21:38:17 +08:00
### Sqlstring
2020-05-01 07:24:59 +08:00
Formats single- and multi-valued variables into a comma-separated string, escapes `'` in each value by `''` and quotes each value with `'` .
```bash
servers = ["test'1", "test2"]
String to interpolate: '${servers:sqlstring}'
Interpolation result: "'test''1','test2'"
```
2020-09-14 14:05:51 +08:00
2022-09-09 21:38:17 +08:00
### Text
2020-09-14 14:05:51 +08:00
Formats single- and multi-valued variables into their text representation. For a single variable it will just return the text representation. For multi-valued variables it will return the text representation combined with `+` .
```bash
servers = ["test1", "test2"]
String to interpolate: '${servers:text}'
Interpolation result: "test1 + test2"
2020-12-21 23:54:01 +08:00
```
2021-02-05 14:16:06 +08:00
2022-09-09 21:38:17 +08:00
### Query parameters
2021-02-05 14:16:06 +08:00
Formats single- and multi-valued variables into their query parameter representation. Example: `var-foo=value1&var-foo=value2`
```bash
servers = ["test1", "test2"]
String to interpolate: '${servers:queryparam}'
Interpolation result: "var-servers=test1& var-servers=test2"
```