grafana/docs/sources/variables/advanced-variable-format-options.md
Diana Payton e7057387a2
Docs: Refactor Variables and Templating content (#23952)
* Moved templating.md

Moved file to a different folder, added alias information, updated menu.yaml

* Split out advanced variable format options from templating.md

* Reworked Advanced variable format options

* Update templating.md

* Moved global variables to another topic

* Moved template files

* Update global-variables.md

* Update global-variables.md

* Update templates-and-variables.md

* made new repeating panels and rows topic

* updated links and menu

* Update advanced-variable-format-options.md

* Update repeat-panels-or-rows.md

* Update menu.yaml

* Update prometheus.md

* Applied Daniel's edits
2020-04-30 16:24:59 -07:00

3.5 KiB

+++ title = "Advanced variable format options" keywords = ["grafana", "templating", "documentation", "guide", "template", "variable"] type = "docs" [menu.docs] name = "advanced-variable-format-options" parent = "variables" weight = 300 +++

Advanced variable format options

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.

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.

General syntax

Syntax: ${var_name:option}

Test the formatting options on the Grafana Play site.

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]].

CSV

Formats multi-value variable as a comma-separated string.

servers = ['test1', 'test2']
String to interpolate: '${servers:csv}'
Interpolation result: 'test1,test2'

Distributed - OpenTSDB

Formats multi-value variable in custom format for OpenTSDB.

servers = ['test1', 'test2']
String to interpolate: '${servers:distributed}'
Interpolation result: 'test1,servers=test2'

Doublequote

Formats single- and multi-valued variables into a comma-separated string, escapes " in each value by \" and quotes each value with ".

servers = ['test1', 'test2']
String to interpolate: '${servers:doublequote}'
Interpolation result: '"test1","test2"'

Glob - Graphite

Formats multi-value variable into a glob (for Graphite queries).

servers = ['test1', 'test2']
String to interpolate: '${servers:glob}'
Interpolation result: '{test1,test2}'

JSON

Formats multi-value variable as a comma-separated string.

servers = ['test1', 'test2']
String to interpolate: '${servers:json}'
Interpolation result: '["test1", "test2"]'

Lucene - Elasticsearch

Formats multi-value variable in Lucene format for Elasticsearch.

servers = ['test1', 'test2']
String to interpolate: '${servers:lucene}'
Interpolation result: '("test1" OR "test2")'

Percentencode

Formats single and multi valued variables for use in URL parameters.

servers = ['foo()bar BAZ', 'test2']
String to interpolate: '${servers:percentencode}'
Interpolation result: 'foo%28%29bar%20BAZ%2Ctest2'

Pipe

Formats multi-value variable into a pipe-separated string.

servers = ['test1.', 'test2']
String to interpolate: '${servers:pipe}'
Interpolation result: 'test1.|test2'

Regex

Formats multi-value variable into a regex string.

servers = ['test1.', 'test2']
String to interpolate: '${servers:regex}'
Interpolation result: '(test1\.|test2)'

Singlequote

Formats single- and multi-valued variables into a comma-separated string, escapes ' in each value by \' and quotes each value with '.

servers = ['test1', 'test2']
String to interpolate: '${servers:singlequote}'
Interpolation result: "'test1','test2'"

Sqlstring

Formats single- and multi-valued variables into a comma-separated string, escapes ' in each value by '' and quotes each value with '.

servers = ["test'1", "test2"]
String to interpolate: '${servers:sqlstring}'
Interpolation result: "'test''1','test2'"