Amazon Managed Service for Prometheus template variables
Use template variables to create dynamic, reusable dashboards that let you change displayed data without editing queries. The Amazon Managed Service for Prometheus data source supports the same template variable features as the core Grafana Prometheus data source.
Before you begin
Before you create template variables, ensure you have:
- Configured the Amazon Managed Service for Prometheus data source.
- A basic understanding of Grafana template variables.
Supported variable types
The data source supports the following template variable types.
Create a query variable
Query variables get their values from your workspace. To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the Amazon Managed Service for Prometheus data source.
- Select a query type and enter the query details.
- Click Apply to save the variable.
Query variable functions
When you select Query as the variable type, the variable editor provides a query type selector with options such as Label names, Label values, Metrics, Query result, and Series query. Each option maps to one of the following Prometheus functions, which you can also enter directly.
Query variable examples
The following examples show how to use each function in a query variable.
Return every label name in the workspace:
label_names()Return all values of the job label:
label_values(job)Return the instance values that exist on the node_cpu_seconds_total metric:
label_values(node_cpu_seconds_total, instance)Return all metrics whose names contain node:
metrics(node)Use query_result to list the instances with high memory usage:
query_result(topk(5, sum by (instance) (node_memory_MemTotal_bytes)))Chain variables
You can reference one variable in another variable’s query to create dependent, or cascading, variables. For example, if you have a job variable, create an instance variable whose values depend on the selected job:
label_values(up{job="$job"}, instance)When you change the job variable, Grafana refreshes the instance variable to show only the instances for that job.
Use variables in queries
Reference a variable in a query with the $variable_name or ${variable_name} syntax. For example, if you have a variable named instance, filter a query by the selected instance:
rate(node_cpu_seconds_total{instance="$instance"}[$__rate_interval])When a variable allows multiple values, use the regex match operator so the query matches any selected value:
rate(node_cpu_seconds_total{instance=~"$instance"}[$__rate_interval])To use multi-value variables, set the Multi-value option on the variable and use the =~ operator. Grafana formats the selected values as a regular expression alternation, such as value1|value2.


