Speed Up Your Dashboard Workflow With Dynamic Template Variable Syntax | Datadog

Speed up your dashboard workflow with dynamic template variable syntax

Author Thomas Sobolik
Author Miranda Kapin

Published: 5月 11, 2021

Template variables enable you to use tags to filter your Datadog dashboards to the hosts, containers, or services you need for faster troubleshooting. However, there are some cases where it may be difficult to use a standard set of template variables to aggregate all of the data you need without creating a complicated, difficult to manage set of variables. For example, you may use tag values that are a subset of another tag. Or, you might be migrating between tagging conventions and need to visualize data from multiple tags.

We’re pleased to announce you can now use the $tempvar.value syntax when defining template variables for your dashboard widgets. This syntax lets you include a template variable’s value within the query when building a graph. This gives you more control over what tags your template variables point to, helping you use fewer template variables while ensuring you can visualize all of the data you need across any tags.

In this post we’ll look at how you can use this new dynamic syntax to define template variables that:

Consolidate template variables by attributing values as a partial string

You can use the $tempvar.value syntax to reduce the number of template variables you use to filter your dashboards. Let’s say you have separate staging environments for different services in your infrastructure. You might tag them with something like env (e.g., env:staging-web-store) and service (e.g., service:web-store). Now, you can use the template variable value as a partial string to streamline your graph queries. Nesting the template variable into the query in this way lets you take advantage of your tagging convention to simplify your template variable set. In this case, you can use the service template variable to specify which staging environment you want to show metrics from.

Using the new syntax, you can form graph queries with a reduced set of template variables.

With the query shown above, specifying web-store as the service in your template variable view would result in the graph pulling the metric from the staging-web-store environment. Leaving the service variable unspecified will graph the metric for each environment definable by the staging-$service.value sequence.

The resulting graph of the above query.

Migrating tagging conventions

If your teams are migrating to a new tagging convention, it can be complicated to ensure that all the relevant metric data you need is included in your dashboard graphs. You can use the $tempvar.val syntax to create “OR” statements in your graph queries that include both. This way, you can ensure that your graphs will show the metrics you want. In the example below, the graph will pull values tagged with the environment key or the env key.

Using the new syntax, you can form graph queries that account for conflicts in your tagging convention(s).

The resulting graph will include every value from the environment we specify, regardless of their key.

Get more flexible network traffic queries

Datadog NPM allows you to query for dependencies between any source or destination. When graphing network performance metrics like volume and TCP retransmits in your dashboards, you can leverage your template variables to build more flexible queries. With the new syntax, you can specify the source and destination of a network connection using the same template variable via, for example, the syntax service:$service.value.

Using the new syntax, you can ensure that your template variables map well to Network Performance Monitoring graph queries.

Then, you can easily filter the resulting graph using the $service variable to see which services are throwing the most retransmits, leading to poor connectivity with their dependencies.

The resulting graph of the above query.

Harness your template variables

With the new dynamic template variable syntax for Datadog, you can easily create adaptive template variables, reducing the number you need to manage and helping ensure no gaps in the data your dashboards visualize. This feature is currently available for all Datadog customers—no additional configuration is required. To learn more about the feature, see our template variable documentation. Or if you’re brand new to Datadog, sign up for a to get started.