Add a query variable

    1. Navigate to the dashboard you want to make a variable for and then click the Dashboard settings (gear) icon at the top of the page.
    2. On the Variables tab, click New.
    3. Enter a Name for your variable.
    4. In the Type list, select Query.
    5. Choose a Hide option:
      • No selection (blank) - The variable dropdown displays the variable Name or Label value. This is the default.
      • Label - The variable dropdown only displays the selected variable value and a down arrow.
      • Variable - No variable dropdown is displayed on the dashboard.
    1. In the Data source list, select the target data source for the query. For more information about data sources, refer to .
    2. In the Refresh list, select when the variable should update options.
      • On Dashboard Load - Queries the data source every time the dashboard loads. This slows down dashboard loading, because the variable query needs to be completed before dashboard can be initialized.
    3. In the Query field, enter a query.
      • The query field varies according to your data source. Some data sources have custom query editors.
      • If you need more room in a single input field query editor, then hover your cursor over the lines in the lower right corner of the field and drag downward to expand.
    4. (optional) In the Regex field, type a regex expression to filter or capture specific parts of the names returned by your data source query. To see examples, refer to Filter variables with regex.
    5. In the Sort list, select the sort order for values to be displayed in the dropdown list. The default option, Disabled, means that the order of options returned by your data source query will be used.
    6. (optional) Enter .
    7. In Preview of values, Grafana displays a list of the current variable values. Review them to ensure they match what you expect.