Enterprise

Templates and variables

Template variables allow you to create dynamic, reusable dashboards. Instead of hard-coding values like metric names or host names, you can use variables that users can change from a drop-down menu.

Supported variable types

The Dynatrace plugin provides data source support for the following Grafana variable types:

Variable typeDescription
QueryDynamically fetches values from your Dynatrace environment. This is the primary variable type for Dynatrace.
Ad-hoc filtersAutomatically applies key-value filters to all metric queries on a dashboard.

Note

You can also use Grafana’s built-in variable types (Custom, Text box, Constant, Interval) with Dynatrace queries. These variables are defined manually and are not populated from Dynatrace. For more information, refer to Variable types.

Query variables

Query variables dynamically fetch values from your Dynatrace environment. To add a new Dynatrace query variable, refer to Add a query variable.

When creating a query variable, select your Dynatrace data source and choose from the following query types:

Query typeDescription
Metric namesReturns a list of all metric names.
Filter keysReturns a list of all possible dimensions (for example, Hostname) that can be used to filter.
Filter values for keyReturns a list of filtered values by a key name or a key name template variable.
Problem status optionsReturns a list of all problem statuses.
Problem impact optionsReturns a list of all problem impacted areas.
Problem severity optionsReturns a list of all problem severity types.
Management ZonesReturns a list of all management zones configured in your Dynatrace environment.
Query EditorAllows you to configure a custom query using the query editor to create a custom template variable. The query must return only 1 column. When your query returns 1 column, click the Apply button. Optionally, a raw query can return two columns named text and value to have different display values for the values.

Regex - (Optional) Filter out any of the returned values from your query with a regular expression.

Note

Multi-value and Include All option support varies by query type. Test your specific use case to verify compatibility.

Ad-hoc filters

Ad-hoc filters let users add filters to all metric queries on a dashboard without editing each panel. The Dynatrace plugin populates filter options from your Dynatrace entity types (such as Host, Process, or Service).

To create an ad-hoc filter variable:

  1. Go to Dashboard settings > Variables > New variable.
  2. Select Ad hoc filters as the variable type.
  3. Select your Dynatrace data source.
  4. Click Apply.

Once configured, a filter bar appears at the top of your dashboard. Users can add filters by selecting an entity type (key) and a specific entity (value). These filters automatically apply to all metric queries on the dashboard.

Variable syntax

The Dynatrace plugin supports multiple variable syntax formats:

SyntaxExampleDescription
$variablename$hostSimple syntax
[[variablename]][[host]]Legacy syntax
${variablename}${host}Advanced syntax with formatting options

Where to use variables

You can use template variables in the following query fields:

Query typeSupported fields
MetricsMetric name, Management Zones, Filter keys, Filter values, Alias, Code mode selector
ProblemsStatus, Impact, Severity, Tags
USQLQuery text
LogsQuery text
Audit LogsFilter text
Direct APIAPI endpoint

Chaining variables

A common pattern is to chain “Filter keys” and “Filter values for key” variables together. This allows users to first select a dimension (like Host or Process), then select a specific value for that dimension.

To chain variables:

  1. Create a variable using Filter keys query type. Name it something like filterKey.
  2. Create a second variable using Filter values for key query type.
  3. In the Filter key name field, enter $filterKey.

Now the second variable’s options dynamically update based on the first variable’s selection.

Additional resources

For more information about variables in Grafana, refer to Templates and variables.