Menu

This is documentation for the next version of Grafana. For the latest stable release, go to the latest version.

Grafana Cloud Enterprise Open source

Azure Monitor template variables

Instead of hard-coding details such as resource group or resource name values in metric queries, you can use variables. This helps you create more interactive, dynamic, and reusable dashboards. Grafana refers to such variables as template variables.

For an introduction to templating and template variables, refer to the Templating and Add and manage variables documentation.

Use query variables

You can specify these Azure Monitor data source queries in the Variable edit view’s Query Type field.

NameDescription
SubscriptionsReturns subscriptions.
Resource GroupsReturns resource groups for a specified. Supports multi-value. subscription.
NamespacesReturns metric namespaces for the specified subscription and resource group.
RegionsReturns regions for the specified subscription
Resource NamesReturns a list of resource names for a specified subscription, resource group and namespace. Supports multi-value.
Metric NamesReturns a list of metric names for a resource.
WorkspacesReturns a list of workspaces for the specified subscription.
LogsUse a KQL query to return values.
Resource GraphUse an ARG query to return values.

Any Log Analytics Kusto Query Language (KQL) query that returns a single list of values can also be used in the Query field. For example:

QueryList of values returned
workspace("myWorkspace").Heartbeat | distinct ComputerVirtual machines
workspace("$workspace").Heartbeat | distinct ComputerVirtual machines with template variable
workspace("$workspace").Perf | distinct ObjectNameObjects from the Perf table
workspace("$workspace").Perf | where ObjectName == "$object" | distinct CounterNameMetric names from the Perf table

Query variable example

This time series query uses query variables:

kusto
Perf
| where ObjectName == "$object" and CounterName == "$metric"
| where TimeGenerated >= $__timeFrom() and TimeGenerated <= $__timeTo()
| where  $__contains(Computer, $computer)
| summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer
| order by TimeGenerated asc

Multi-value variables

It is possible to select multiple values for Resource Groups and Resource Names and use a single metrics query pointing to those values as long as they:

  • Belong to the same subscription.
  • Are in the same region.
  • Are of the same type (namespace).

Also, note that if a template variable pointing to multiple resource groups or names is used in another template variable as a parameter (e.g. to retrieve metric names), only the first value will be used. This means that the combination of the first resource group and name selected should be valid.