Introducing Wildcard-Filtered Metric Queries | Datadog

Introducing wildcard-filtered metric queries

Author Kathy Lin
Author Jonathan Epstein

Published: March 5, 2021

Tags are essential for your teams to quickly and efficiently filter through and find the information they need among the huge scope of data generated by your cloud infrastructure. Given that modern environments are always changing, with hosts and containers continuously being added or replaced, you need to be able to dynamically scope your queries so that you’re not rewriting the same searches over and over again.

To help ensure that you can efficiently monitor and alert on the exact data you need, Datadog now allows you to build queries in your dashboards, notebooks, and monitors using wildcard-filtered metric queries. The wildcard asterisk (*) is used to signify the set of all tag values that match a given prefix or suffix, thus providing a quick way to specify large scopes of results without using complex or repetitive filtering conventions. Wildcard-filtered metric queries adapt to your dynamic infrastructure.

How wildcard-filtered metric queries work

To create a wildcard-filtered metric query, simply append the * character to the prefix or suffix of the group of tag values you want to surface. Instead of setting up multiple queries to represent a region or having to update a boolean-filtered metric query to include new Western Availability Zones (AZs), you can simply filter your metrics with availability-zone:us-west-* to track all hosts in your AWS West AZs. Or if you use Kubernetes to deploy a web application and want to monitor memory usage across pods whose names start with “metrics-server*”, you would query with pod_name:metrics-server* as shown below:

Wildcard filtering allow you to include a wide, fluid scope of metrics in your queries.
Wildcard filtering allow you to include a wide, dynamic scope of metrics in your queries.

Filters for dynamic environments

Because wildcard filtering lets you build queries that take into account changes in your infrastructure, it is invaluable for tracking tags attached to assets that frequently launch or churn, such as VMs, devices, and containers.

For instance, if you run a large datacenter, the number of file systems you need to monitor might frequently change as applications create temporary ones. These temporary file systems automatically have 100 percent disk usage, meaning that if you are monitoring disk space usage across your infrastructure, they can make it difficult to get an accurate measure. Using wildcard filtering, you can build queries that collect metrics data from the full scope of storage devices while excluding temporary devices—even if they go live after the query is written. For example, the following query returns disk usage for all relevant devices except for ones starting with /dev/loop, which represent file system mounts:

avg:system.disk.in_use{!device:/dev/loop*} by {host,device}
Use wildcards to exclude certain tag patterns in your queries.
Use wildcards to exclude certain tag patterns in your queries.

As your business grows, applications mature and become versioned, wildcard filter queries can help you quickly understand the performance differences between version. For instance, if you’re interested in knowing how much CPU each version of your application named “ami” uses, you can use the filter: image:ami*

sum:docker.cpu.usage{image:ami*} by {image}
You can use wildcard-filtered queries across Datadog monitoring tools, including custom dashboards, notebooks and monitors.
You can use wildcard-filtered metric queries across the entire Datadog platform, including custom dashboards, notebooks and monitors.

You can also combine wildcard and boolean syntax for more powerful, complex filters when querying metrics. For instance, if you’re running a Java application and want to find the average garbage collection time across production instances matching instance:app*prod, you can specify an instance prefix and suffix with the following query:

avg:jvm.gc.major_collection_time{instance:app* AND instance:*prod}

The star* of the show

Along with boolean-filtered metric queries, wildcard filtering gives you more flexibility than ever when building queries and allows you to dynamically retrieve telemetry from your ever-changing asset inventory. You can start using wildcard filtering in your Datadog dashboards, widgets, and notebooks right now. And if you’re not already a Datadog customer, get started with a .