Variable syntax

    • ${var_name} Use this syntax when you want to interpolate a variable in the middle of an expression.
    • ${var_name:<format>} This format gives you more control over how Grafana interpolates values. Refer to Advanced variable format options for more detail on all the formatting types.
    • [[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.

    For advanced syntax to override data source default formatting, refer to .

    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.

    Syntax: ${var_name:option}

    Test the formatting options on the Grafana Play site.

    An alternative syntax (that might be deprecated in the future) is [[var_name:option]].

    CSV

    Formats variables with multiple values as a comma-separated string.

    Distributed - OpenTSDB

    Formats variables with multiple values in custom format for OpenTSDB.

    1. servers = ['test1', 'test2']
    2. String to interpolate: '${servers:distributed}'
    3. 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 ".

    1. servers = ['test1', 'test2']
    2. Interpolation result: '"test1","test2"'

    Glob - Graphite

    Formats variables with multiple values into a glob (for Graphite queries).

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

    Formats variables with multiple values as a comma-separated string.

    Lucene - Elasticsearch

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

    Percentencode

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

    1. servers = ['foo()bar BAZ', 'test2']
    2. Interpolation result: 'foo%28%29bar%20BAZ%2Ctest2'

    Pipe

    Formats variables with multiple values into a pipe-separated string.

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

    Raw

    Turns off data source-specific formatting, such as single quotes in an SQL query.

    Formats variables with multiple values into a regex string.

    1. servers = ['test1.', 'test2']
    2. String to interpolate: '${servers:regex}'

    Singlequote

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

    1. servers = ['test1', 'test2']
    2. String to interpolate: '${servers:singlequote}'
    3. 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 '.

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

    Text

    Query parameters

    Formats single- and multi-valued variables into their query parameter representation. Example: var-foo=value1&var-foo=value2

    1. servers = ["test1", "test2"]
    2. Interpolation result: "var-servers=test1&var-servers=test2"