Join us at the Dash conference! July 16-17, NYC

Template Variables

Dashboard template variables apply a new scope to one or more widgets in your dashboard, allowing you to dynamically explore metrics across different sets of tags by using variables instead of specific tags.

Define a Template Variable

New dashboards start with a keyless template variable applied. Click on the pencil icon to open the template variable edit mode:

Edit template variable

Once in the edit mode click on Add Variable + to create your first Template Variable, it is defined by:

  • A Name -Mandatory-: Value of your Template Variable displayed in your graphs query.
  • A Tag Group -Mandatory-: If your tags follow the tags best practice with a key:value format, the Tag Group is the key of your tags.
  • A Default Tag -Optional-: Default value for your Template Variable Tag Group.

Once created, notice that you have statistics upon your template variables usage in your graphs. In the picture below, the template variable is not used in both graph of the dashboard:

statistic TV

Decide if you want to remove/add this template variable to all of your graph widgets with the respective Remove From All and Add to All buttons.

Use Template Variables

Widgets

Once you have defined a template variable, it appears in the options displayed in the from field:

Template variable in graphs

After the graph is saved, the value of this template variable is the one selected on top of your dashboard:

Selecting template variables

Template variables with Logs and APM queries

Template variables work on log and APM query based widgets—since metrics, logs, and APM share the same tags. Additionally, it is possible to define specific log/APM template variables based on your log or APM facets. These template variables start with @.

log template variables

Note: Using the Add to all button adds this template variable to all log/APM widgets only.

Note widget

Even if the note widget doesn’t contain any graphs, you can display:

  • The selected template variable with the $<TEMPLATE_VARIABLE_KEY> syntax.
  • The selected template variable value in it with the $<TEMPLATE_VARIABLE_KEY>.value syntax.

For instance, with the following note widget configuration:

$env

$env.value

Selecting the dev value for the $env template variable outputs the following result:

Note widget template variables

Events Overlay

The event overlay search allows you to correlate metrics and events. Use template variables to find events that share certain tags with the metrics in your dashboard. The event overlay search is applied through an individual graph.

Values from dashboard template variables can be directly captured by using the $<TEMPLATE_VARIABLE_KEY>.value syntax in the event search field.

Note: Dashboard template variables must be metric tags; event-supplied tags cannot be used as dashboard template variables.

Single Template variable

For example, to search for events in the event stream with the same region tag, use: tags:region:$region.value.

tv5

In the following example, the template variable resolves to tags:region:ap-south-1. After those events are brought up in the event search overlay, the timing of the events are marked by pink bars in the graphs to show the timing of events:

tv7

Multiple Template variables

Use multiple template variables in the search field to display all corresponding events tagged. The following example uses the query tags:role:$role.value,env:$env.value

tv8

Associating Template variables with other Tags

Use the $<TEMPLATE_VARIABLE_KEY>.value syntax to capture the resolved key:value from a given template variable and use it with other filters.

Find below an example that uses the env tags together with the hosts tag in the search term tags:env:$env.value hosts:$host.value

tv9

Further Reading